Hi,
My code throws the exception listed below. I think, it's because hibernate doesn't flush my CUD operations immediately.
I have typical spring configuration with hibernate: hibernate transaction manager, all methods wired into transaction, with propagation required. It's a very usual configuration, so I won't even list it here.
UPDATED: I've read this blog
http://www.jroller.com/comments/maxi...ned_unexpected,
which says this kind of exception occurs, "When your code is trying to update objects and some of them getting changed at the same time in different transaction."
I don't undersand, how how is this possible, since I everything happens in one transaction....
p.s. one more thing: I think, spring is ignoring the
hibernate.transaction.flush_before_completion attribute. I mean, I found reference to FLUSH_EAGER in HibernateAccessor, but
there are no references to this attribute, which I would (logically) expect.
UPDATED: the problem has been solved by using hibernate's merge() function instead of saveOrUpdate
FINE: Retrieved value [org.springframework.orm.hibernate3.SessionHolder@8 08680] for key [org.hibernate.impl.SessionFactoryImpl@76b359] bound to thread [main]
2.9.2005 16:25:53 org.springframework.transaction.support.Transactio nSynchronizationManager getResource
FINE: Retrieved value [org.springframework.orm.hibernate3.SessionHolder@8 08680] for key [org.hibernate.impl.SessionFactoryImpl@76b359] bound to thread [main]
2.9.2005 16:25:53 org.springframework.orm.hibernate3.HibernateTempla te execute
FINE: Found thread-bound Session for HibernateTemplate
2.9.2005 16:25:53 org.springframework.orm.hibernate3.HibernateTempla te execute
FINE: Not closing pre-bound Hibernate Session after HibernateTemplate
2.9.2005 16:28:21 org.springframework.orm.hibernate3.HibernateInterc eptor invoke
FINE: Not closing pre-bound Hibernate Session after HibernateInterceptor
2.9.2005 16:28:21 org.springframework.transaction.interceptor.Transa ctionAspectSupport doCommitTransactionAfterReturning
FINE: Invoking commit for transaction on cz.aura.isl.katalog.davky.domain.logic.export.IExp ortKataloguService.exportPolozek
2.9.2005 16:28:21 org.springframework.transaction.support.AbstractPl atformTransactionManager triggerBeforeCommit
FINE: Triggering beforeCommit synchronization
2.9.2005 16:28:21 org.springframework.transaction.support.AbstractPl atformTransactionManager triggerBeforeCompletion
FINE: Triggering beforeCompletion synchronization
2.9.2005 16:28:21 org.springframework.transaction.support.AbstractPl atformTransactionManager processCommit
FINE: Initiating transaction commit
2.9.2005 16:28:21 org.springframework.orm.hibernate3.HibernateTransa ctionManager doCommit
FINE: Committing Hibernate transaction on Session [org.hibernate.impl.SessionImpl@1eaf25d]
2.9.2005 16:28:21 org.hibernate.event.def.AbstractFlushingEventListe ner performExecutions
SEVERE: Could not synchronize database state with session
org.hibernate.HibernateException: Unexpected row count: 0 expected: 1
at org.hibernate.jdbc.NonBatchingBatcher.addToBatch(N onBatchingBatcher.java:32)
at org.hibernate.persister.entity.BasicEntityPersiste r.update(BasicEntityPersister.java:1982)
at org.hibernate.persister.entity.BasicEntityPersiste r.updateOrInsert(BasicEntityPersister.java:1909)
at org.hibernate.persister.entity.BasicEntityPersiste r.update(BasicEntityPersister.java:2149)
at org.hibernate.action.EntityUpdateAction.execute(En tityUpdateAction.java:75)
at org.hibernate.engine.ActionQueue.execute(ActionQue ue.java:239)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:223)
at org.hibernate.engine.ActionQueue.executeActions(Ac tionQueue.java:137)
at org.hibernate.event.def.AbstractFlushingEventListe ner.performExecutions(AbstractFlushingEventListene r.java:274)
at org.hibernate.event.def.DefaultFlushEventListener. onFlush(DefaultFlushEventListener.java:27)
at org.hibernate.impl.SessionImpl.flush(SessionImpl.j ava:730)
at org.hibernate.impl.SessionImpl.managedFlush(Sessio nImpl.java:324)
at org.hibernate.transaction.JDBCTransaction.commit(J DBCTransaction.java:86)
at org.springframework.orm.hibernate3.HibernateTransa ctionManager.doCommit(HibernateTransactionManager. java:490)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.processCommit(AbstractPla tformTransactionManager.java:495)
at org.springframework.transaction.support.AbstractPl atformTransactionManager.commit(AbstractPlatformTr ansactionManager.java:468)
at org.springframework.transaction.interceptor.Transa ctionAspectSupport.doCommitTransactionAfterReturni ng(TransactionAspectSupport.java:258)
at org.springframework.transaction.interceptor.Transa ctionInterceptor.invoke(TransactionInterceptor.jav a:106)
at org.springframework.aop.framework.ReflectiveMethod Invocation.proceed(ReflectiveMethodInvocation.java :144)
at org.springframework.aop.framework.JdkDynamicAopPro xy.invoke(JdkDynamicAopProxy.java:174)
at $Proxy12.exportPolozek(Unknown Source)
at cz.aura.isl.katalog.davky.domain.logic.export.Expo rtKataloguServiceImplTest.testexportPolozek(Export KataloguServiceImplTest.java:40)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Native MethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(De legatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at junit.framework.TestCase.runTest(TestCase.java:154 )
at junit.framework.TestCase.runBare(TestCase.java:127 )
at junit.framework.TestResult$1.protect(TestResult.ja va:106)
at junit.framework.TestResult.runProtected(TestResult .java:124)
at junit.framework.TestResult.run(TestResult.java:109 )
at junit.framework.TestCase.run(TestCase.java:118)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.runTests(RemoteTestRunner.java:474)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.run(RemoteTestRunner.java:342)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRu nner.main(RemoteTestRunner.java:194)


Reply With Quote