Announcement Announcement Module
Collapse
No announcement yet.
batch update error using Hibernate 3 Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • batch update error using Hibernate 3

    Hi all,

    Does anyone have an idea what causes the following error?

    Code:
    Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
    
    org.springframework.orm.hibernate3.HibernateSystemException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1; nested exception is org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1 at org.hibernate.jdbc.BatchingBatcher.checkRowCount(BatchingBatcher.java:92) at org.hibernate.jdbc.BatchingBatcher.checkRowCounts(BatchingBatcher.java:78) at org.hibernate.jdbc.BatchingBatcher.doExecuteBatch(BatchingBatcher.java:57) at org.hibernate.jdbc.AbstractBatcher.executeBatch(AbstractBatcher.java:172) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226) at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:141) at org.hibernate.event.def.AbstractFlushingEventListener.performExecutions(AbstractFlushingEventListener.java:274) at org.hibernate.event.def.DefaultFlushEventListener.onFlush(DefaultFlushEventListener.java:27) at org.hibernate.impl.SessionImpl.flush(SessionImpl.java:678) at org.hibernate.impl.SessionImpl.managedFlush(SessionImpl.java:309) at org.hibernate.transaction.JDBCTransaction.commit(JDBCTransaction.java:86) at org.springframework.orm.hibernate3.HibernateTransactionManager.doCommit(HibernateTransactionManager.java:470) at org.springframework.transaction.support.AbstractPlatformTransactionManager.commit(AbstractPlatformTransactionManager.java:401) at org.springframework.transaction.interceptor.TransactionAspectSupport.doCommitTransactionAfterReturning(TransactionAspectSupport.java:256) at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:67) at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:144) at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:174) at $Proxy0.removeColumnMapper(Unknown Source) at za.co.telkom.ubr.service.ConfigurationServiceTest.testRemoveColumnMapper(ConfigurationServiceTest.java:235) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    I'm trying to remove a row from an intersection table. I'm using Hibernate 3 and Spring 1.2 rc1

    Thanks,
    Stefan

  • #2
    I have found I was getting this error today too. It was relating to trying to delete a bean, and then save a bean (another reference to the same one).

    Here is what I was doing:
    I had a form where I would pass in a collection of mapped hibernate beans (as a nested bean on a struts form)
    when the form handler wanted to save the changes, I was gathering the collection from the form, but before i did a save for each of them, I was getting a collection of existing items from the database, and deleting them all.
    This was to handle the case when an item did exist but got removed from the form, the assumption being that beans i had from the form were still populated with all the details (id, modification timestamps) so it was ok to just delete the old things.
    And this is when the exception would come for me.

    Here is how I fixed it:
    I changed my hibernate mapped bean to implement the equals() (my bad, should have had that there before) where it would inspect based on the primary key value . So in the get all existing collections and loop to attempt to delete them, i first inspect to see if the bean i would want to delete is still contained in the collection of ones i just got back from the form. if it is, don't delete it.

    Here is a snippet of my code where i
    - get the items from the form (instances of mapped hibernate beans)
    - get the existing ones in the database
    - delete ones from the existing collection that are not in the form collection (were removed)
    - save the collection from the form (and apply other business rules)

    Code:
            Collection col = model.getQueryParameters();  // from form
    
            Collection existing = queryParameterDAO.findForQueryId(queryId);
    
            // whack out existing entries
    
            for (Iterator it = existing.iterator(); it.hasNext();) {
                QueryParameter queryParameter = (QueryParameter)it.next();
                if (col.contains(queryParameter)) {
                    // this item is still in use, do not delete it.
                    if (log.isDebugEnabled()) {
                        log.debug("not deleting item still in use: " + queryParameter);
                    }
                    continue;
                }
                if (log.isDebugEnabled()) {
                    log.debug("removing no longer used existing item: " + queryParameter);
                }
                queryParameterDAO.physicalDelete(queryParameter);
            } // for each existing
            
            // save our current ones on the form
            int displayOrder = 0;
            log.debug("saving " + col.size() + " current queryParameter entries");
            for (Iterator it = col.iterator(); it.hasNext();) {
                QueryParameter queryParameter = (QueryParameter) it.next();
                log.debug("saving: " + queryParameter);
                queryParameter.setQueryId(queryId); // stamp it on, in case it was not
                queryParameter.setDisplayOrder(new Integer(++displayOrder)); // stamp display order
                queryParameterDAO.save(sess, queryParameter);
            } // for queryParameter

    Comment

    Working...
    X