-->
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.  [ 2 posts ] 
Author Message
 Post subject: PreUpdateEvent same collection in oldState and state
PostPosted: Fri Jul 06, 2007 2:01 am 
Newbie

Joined: Fri Jun 17, 2005 2:07 am
Posts: 19
Location: Berne, Switzerland
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.2.2
Mapping documents:
<hibernate-mapping>

<class name="ch.rtc.tech.test.BaDbs_Person" table="PERSON">
...

<version name="version"
<column name="version"/>
</version>

<set name="adressen" inverse="true" cascade="all" order-by="ort asc">
<key column="FK_PERSON"/>
<one-to-many class="ch.rtc.tech.test.BaDbs_Adresse"/>
</set>
...
</class>

</hibernate-mapping>

Code between sessionFactory.openSession() and session.close():

BaDbs_Person person2 = (BaDbs_Person) session.get(BaDbs_Person.class, key);
assertEquals(3, person2.getAdressen().size());
BaDbs_Adresse adr = createAdresse(test, id, 4);
person2.addAdresse(adr);

Full stack trace of any exception that occurs:
no exception
Name and version of the database you are using:
hsqldb 1.8.0

i have a PreUpdateListener configured for the session factory.
when adding a new child (BaDbs_Adresse) to the parent a PreUpdateEvent is fired for the parent as expected. When i inspect the state/oldState of the event both contain the same instance of the child collection. The collection already contains the newly added child.

is this a bug in the event ?
it looks like if the event is only fired because of the changed 'version' attribute. see also http://opensource.atlassian.com/project ... e/HHH-2616

thanks
jakob


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 29, 2008 2:53 pm 
Newbie

Joined: Tue Jan 29, 2008 2:38 pm
Posts: 2
I also have problems with the fact that the oldState and the state of the child collection appear to be the same although the child collection members have been modified.

This is how I arrive at this situation:
1)I session.load() the parent from the database.
2)I Hibernate.initialize() the child collection to avoid LazyInstantiationException.
3)I session.evict() the parent to detach it from the session.
4)I modify one of the properties of the children in the collection.
5)I session.merge() the parent with the collection of modified children to reattach it to the session and save it to the database.
6)I commit the changes.
7)I capture the PreUpdateEvent and look for the oldState of the childCollection but it is identical to the state.

Is there any way to capture the oldState of a childCollection, using my strategy or a completely different strategy? I need to create a validator that does the validation by comparing the oldState (in the database) and the new state (about to be saved to the database).


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 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.