Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Problem
I have problem that Hibernate tries to update a non-existing row in the database. It only does this if I run a Maven/Junit-test in a serie of independent tests.
If I run it alone, it runs fine.
It maybe to much to print all relevant mapping fiels, and SQL-output, because it is about compicated objects that are mapped.
The problem occurs in the object HierarchicalObjectID which is a child of ObjectID.
I did analyze all SQL statements that run before in the serie, if there was something left, or so. This is not the case.
It looks to me that Hibernate does not always complete database-sessions, and that the error is related to this.
Somtimes I find in a trace following:
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
DEBUG [Finalizer] (ConnectionManager.java:369) - running Session.finalize()
Please ask for information, if you need more, i will provide you with all information, I only did not want to overload you initially
Thanks in advance
Bert Verhees
Hibernate version: 3.0.5
Mapping documents:
<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE hibernate-mapping
PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="org.openehr.rm.support.identification.ObjectID"
abstract="true"
table="object_id">
<id name="_id" column="_id" type="long">
<generator class="identity"/>
</id>
<discriminator/>
<property name="value" column="_value" type="string"/>
<subclass name="org.openehr.rm.support.identification.HierarchicalObjectID"
discriminator-value="HierarchicalObjectID"/>
<subclass name="org.openehr.rm.support.identification.ArchetypeID"
discriminator-value="ArchetypeID"/>
<subclass name="org.openehr.rm.support.identification.TerminologyID"
discriminator-value="TerminologyID"/>
<subclass name="org.openehr.rm.support.identification.ObjectVersionID"
discriminator-value="ObjectVersionID"/>
</class>
</hibernate-mapping>
Code between sessionFactory.openSession() and session.close():
(springframework)dao related save of an object
Full stack trace of any exception that occurs:
org.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:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
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:730)
at org.springframework.orm.hibernate3.RunningHibernateAccessor.flushIfNecessary(RunningHibernateAccessor.java:394)
at org.springframework.orm.hibernate3.RunningHibernateTemplate.execute(RunningHibernateTemplate.java:366)
at org.springframework.orm.hibernate3.RunningHibernateTemplate.save(RunningHibernateTemplate.java:612)
at zorggemak.dao.orm.openehr.rm.common.changecontrol.ContributionDaoImpl.save(ContributionDaoImpl.java:20)
at zorggemak.dao.orm.openehr.rm.common.changecontrol.ContributionDaoTest.testSave(ContributionDaoTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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.java: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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:210)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:122)
at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement
ERROR [main] (AbstractFlushingEventListener.java:277) - Could not synchronize database state with session
org.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:174)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:226)
at org.hibernate.engine.ActionQueue.executeActions(ActionQueue.java:137)
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:730)
at org.springframework.orm.hibernate3.RunningHibernateAccessor.flushIfNecessary(RunningHibernateAccessor.java:394)
at org.springframework.orm.hibernate3.RunningHibernateTemplate.execute(RunningHibernateTemplate.java:366)
at org.springframework.orm.hibernate3.RunningHibernateTemplate.save(RunningHibernateTemplate.java:612)
at zorggemak.dao.orm.openehr.rm.common.changecontrol.ContributionDaoImpl.save(ContributionDaoImpl.java:20)
at zorggemak.dao.orm.openehr.rm.common.changecontrol.ContributionDaoTest.testSave(ContributionDaoTest.java:41)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.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.java: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 junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at sun.reflect.GeneratedMethodAccessor13.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.junit.JUnitTestSet.execute(JUnitTestSet.java:210)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.executeTestSet(AbstractDirectoryTestSuite.java:135)
at org.apache.maven.surefire.suite.AbstractDirectoryTestSuite.execute(AbstractDirectoryTestSuite.java:122)
at org.apache.maven.surefire.Surefire.run(Surefire.java:129)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:585)
at org.apache.maven.surefire.booter.SurefireBooter.runSuitesInProcess(SurefireBooter.java:225)
at org.apache.maven.surefire.booter.SurefireBooter.main(SurefireBooter.java:747)
Name and version of the database you are using:MySQL 5.0x
The generated SQL (show_sql=true):
too much, I explain the problem, if SQL is needed, I will print it
I print parts of it in the details of the problem description
Debug level Hibernate log excerpt:
RunningHibernate: update object_id set _value=? where _id=?
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.support.identification.TerminologyID#8]
DEBUG [main] (NullableType.java:59) - binding 'language-test' to parameter: 1
DEBUG [main] (NullableType.java:59) - binding '8' to parameter: 2
DEBUG [main] (BatchingBatcher.java:27) - Adding to batch
DEBUG [main] (BatchingBatcher.java:54) - Executing batch size: 2
ERROR [main] (BatchingBatcher.java:60) - Exception executing batch:
org.hibernate.StaleStateException: Batch update returned unexpected row count from update: 0 actual row count: 0 expected: 1
Problems with Session and transaction handling?
Read this:
http://hibernate.org/42.html