-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 
Author Message
 Post subject: org.hibernate.StaleStateException: Batch update returned une
PostPosted: Thu Dec 28, 2006 8:24 am 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 9:33 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Do you commit or rollback any left tx after each test? Do you check (in setUp() method, for example) that the session is not open, or at least that the session is never shared between tests?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 12:12 pm 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
Thanks Batmat I enclosed every database-action now with transaction code, like this
(please take care, the way of deleting objects over the "find" construct is not optimal, but is done to do some testing, that is not the problem)


Transaction t = getHibernateTemplate().getSessionFactory().getCurrentSession().beginTransaction();
try{
getHibernateTemplate().deleteAll(getHibernateTemplate().find("from org.openehr.rm.common.resource.TranslationDetails"));
getHibernateTemplate().flush();
t.commit();
}catch(RuntimeException e){
t.rollback();
throw e;
}

Now I get another error, you see the newbie mark at my name, so, please help me, I will not forget to change the credits for you

Here is the new exception/error message, maybe it is just a little thing to do?
"No Hibernate Session bound to thread, and configuration does not allow creation of non-transactional one here"

Thanks in advance

Bert


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 2:30 pm 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
I guess this is the first line, when you try and retrieve the session, which throws the exception, right?

What does your hibernate.cfg.xml file contain? Does it contain the following line:
Code:
<property name="current_session_context_class">thread</property>

If not, you should read about this special method "getCurrentSession()" on the SessionFactory object and about tx handling with Hibernate: http://hibernate.org/42.html and the reference doc: http://www.hibernate.org/hib_docs/v3/re ... emarcation

Don't retrieve the session this way, but just by calling getSession() inside a method of a subclass of HibernateDao. We also use Spring for this purpose and very rarely access directly the sessionfactory like you do in your code.

To finish, I would advice you even not to manage your tx inside your code, but in the Spring context file. Use for example the TransactionProxyFactoryBean class which you'll use as a proxy for your real DAO. This class will automatically start or not a tx depending on the method name.

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 28, 2006 2:58 pm 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
Thanks, I have it repaired now, thanks to you

I must read more about Transactions and Sessions, but now I understand the problem


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 10:50 am 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
batman, I hope you are still listening, I did quite some study on transactions, etc. I pinned the problem a bit down.

I have two objects to save. Link and Contribution

The object Link has a property TerminologyID, which is an object. Child object form object_id, that is where it is stored, it is in hbm.xml like this

<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>


This happens:

Hibernate: insert into object_id (_value, class) values (?, 'TerminologyID')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.support.identification.TerminologyID#<null>]
DEBUG [main] (NullableType.java:59) - binding 'language-test' to parameter: 1
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 593


Later on it is deleted (this is part of the test)
Hibernate: delete from object_id where _id=?
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (NullableType.java:59) - binding '593' to parameter: 1
DEBUG [main] (BatchingBatcher.java:27) - Adding to batch
DEBUG [main] (BasicEntityPersister.java:2027) - Deleting entity: [org.openehr.rm.datatypes.text.DvText#514]
DEBUG [main] (BatchingBatcher.java:54) - Executing batch size: 1
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement


Everything is captured in transactions, openSession and closesessions, and I use MyuSQL with InnoDB-tables.

No I come to Contribution, which also has some terminology to store, I show you some more, because here is where the error occurs:

DEBUG [main] (ConnectionManager.java:296) - opening JDBC connection
DEBUG [main] (JDBCTransaction.java:50) - current autocommit status: true
DEBUG [main] (JDBCTransaction.java:52) - disabling autocommit



We create a object HierarchicalObjectID, which is also a child of ObjectID, see above in hbm-file

Hibernate: insert into object_id (_value, class) values (?, 'HierarchicalObjectID')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.support.identification.HierarchicalObjectID#<null>]
DEBUG [main] (NullableType.java:59) - binding '1.2.840.113554.1.3.6' to parameter: 1
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 596
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement


As you can see 596 as ID is returned. This is OK, because it is in the same table and must have a later ID. (_id)

We need to store the object (with HierarchicalObjectID as PartyReference which is a child of object_reerence, no error here, but I show you anyway, to be sure

DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.support.identification.PartyReference
DEBUG [main] (BasicEntityPersister.java:1732) - Inserting entity: org.openehr.rm.support.identification.PartyReference (native id)
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (AbstractBatcher.java:324) - insert into object_reference (id, type_string, namespace_string, dummy, class) values (?, ?, ?, ?, 'PartyReference')
Hibernate: insert into object_reference (id, type_string, namespace_string, dummy, class) values (?, ?, ?, ?, 'PartyReference')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.support.identification.PartyReference#<null>]
DEBUG [main] (NullableType.java:59) - binding '596' to parameter: 1
DEBUG [main] (NullableType.java:59) - binding 'PARTY' to parameter: 2
DEBUG [main] (NullableType.java:59) - binding 'DEMOGRAPHIC' to parameter: 3
DEBUG [main] (NullableType.java:52) - binding null to parameter: 4
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 148
DEBUG [main] (AbstractBatcher.java:298) - about to close PreparedStatement (open PreparedStatements: 1, globally: 1)
DEBUG [main] (AbstractBatcher.java:416) - closing statement


Then something strange happens, he starts finding objects from a previous test, they cannot exist anymore, they do not exist in the database, they do not exist in memory. It must be in hibernate they hang around

DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.support.identification.PartyReference
DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.support.identification.PartyReference
DEBUG [main] (Cascades.java:153) - cascading to saveOrUpdate: org.openehr.rm.datatypes.text.DvCodedText
DEBUG [main] (Cascades.java:526) - id unsaved-value: 0
DEBUG [main] (AbstractSaveEventListener.java:410) - transient instance of: org.openehr.rm.datatypes.text.DvCodedText
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:159) - saving transient instance
DEBUG [main] (AbstractSaveEventListener.java:133) - saving [org.openehr.rm.datatypes.text.DvCodedText#<null>]
DEBUG [main] (AbstractSaveEventListener.java:195) - executing insertions
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.text.DvCodedText
DEBUG [main] (Cascades.java:153) - cascading to saveOrUpdate: org.openehr.rm.datatypes.text.CodePhrase
DEBUG [main] (Cascades.java:526) - id unsaved-value: 0
DEBUG [main] (AbstractSaveEventListener.java:410) - transient instance of: org.openehr.rm.datatypes.text.CodePhrase
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:159) - saving transient instance
DEBUG [main] (AbstractSaveEventListener.java:133) - saving [org.openehr.rm.datatypes.text.CodePhrase#<null>]
DEBUG [main] (AbstractSaveEventListener.java:195) - executing insertions
DEBUG [main] (Cascades.java:836) - processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.text.CodePhrase
DEBUG [main] (Cascades.java:153) - cascading to saveOrUpdate: org.openehr.rm.support.identification.TerminologyID
DEBUG [main] (Cascades.java:526) - id unsaved-value: 0
DEBUG [main] (AbstractSaveEventListener.java:414) - detached instance of: org.openehr.rm.support.identification.TerminologyID

DEBUG [main] (DefaultSaveOrUpdateEventListener.java:200) - updating detached instance
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:246) - updating [org.openehr.rm.support.identification.TerminologyID#593]
DEBUG [main] (DefaultSaveOrUpdateEventListener.java:296) - updating [org.openehr.rm.support.identification.TerminologyID#593]

DEBUG [main] (Cascades.java:861) - done processing cascade ACTION_SAVE_UPDATE for: org.openehr.rm.datatypes.text.CodePhrase
DEBUG [main] (BasicEntityPersister.java:1732) - Inserting entity: org.openehr.rm.datatypes.text.CodePhrase (native id)
DEBUG [main] (AbstractBatcher.java:290) - about to open PreparedStatement (open PreparedStatements: 0, globally: 0)
DEBUG [main] (AbstractBatcher.java:324) - insert into data_value (terminology_id, code_string, class) values (?, ?, 'CodePhrase')
Hibernate: insert into data_value (terminology_id, code_string, class) values (?, ?, 'CodePhrase')
DEBUG [main] (AbstractBatcher.java:378) - preparing statement
DEBUG [main] (BasicEntityPersister.java:1612) - Dehydrating entity: [org.openehr.rm.datatypes.text.CodePhrase#<null>]

DEBUG [main] (NullableType.java:59) - binding '593' to parameter: 1
DEBUG [main] (NullableType.java:59) - binding 'ISO-8859-1' to parameter: 2
DEBUG [main] (IdentifierGeneratorFactory.java:37) - Natively generated identity: 516


As you can see in the red lines, it seems to pick up an old object of TerminologyID, with same content.

To be clear, this is in two seperate Junit-tests, each junit-test with its own test-class, test-method, openSession and close session, begintransaction and commit, I even tested it with hashCode, the terminologyID from Link is another intance than the terminologyID from Contribution, but they have the same ID and the same content.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 11:10 am 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
Stop the proesses, I found it, took me a long time, but I did not write the code on my own

The base-class on which the test-class is based (and which is a child of TestCase, had following declaration

protected static final TerminologyID LANGUAGE = new TerminologyID("language-test");

This means to hibernate, it can use the same terminologyID, although the previous one is deleted, from the database.

I don't understand why, but this is the solution, I replaced this statemnt by just creating a new TerminologyID("language-test"); al the time I need it.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 11:15 am 
Expert
Expert

Joined: Tue Dec 28, 2004 7:02 am
Posts: 573
Location: Toulouse, France
Well, lot of things to read. I'm not sure I stored everything in mind. Did you verify you don't use the same session between those two tests. Because there's sometimes a difference between what we think we do and what we actually do :-).

Did you also commit() at the end of the previous test? As you say data is present in db, I guess you see it with an external client, like SQL/Plus or else?

_________________
Baptiste
PS : please don't forget to give credits below if you found this answer useful :)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 02, 2007 11:21 am 
Beginner
Beginner

Joined: Mon Nov 20, 2006 9:06 am
Posts: 29
protected static final TerminologyID LANGUAGE = new TerminologyID("language-test");

This line was the problem

I had two test-classes

LinkDaoTest and ContributionDaoTest

both inherit from DaoTestBase to do some common things, for example,c reate a TerminologyID (object)

DaoTestBase inherits from TestCase (junit)

This protected final TerminologyID was somehow remembered inside hibernate (it was deleted from the daabase as being a part of Link), so it at a next test (Contribution), instead of creating a new one, it used the previous one (which was not anymore in the database, but it also did not create a new one in the database), and in this way Contribution had an TerminologyID-object which was not linked to a database-object.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.