-->
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: Collections are always dirty, even when they are not.
PostPosted: Thu Aug 04, 2005 4:17 pm 
Newbie

Joined: Thu Aug 04, 2005 3:50 pm
Posts: 5
I have a bi-directional relationship between A and C.

A has a one-to-many with C, and C has a many-to-one with A (*.hbm.xml below).

My issue is that the collection of C's is always updated upon saving A, even if the collection was never modified. For example:


// session is a Hibernate session

String hql = "select a from A a join fetch a.Cs where a.APK=1";

Query q = session.createQuery(hql);

List results = q.list();

A a = (A) results.get(0);

session.beginTransaction();

session.saveOrUpdate(a);

session.commitTransaction();

session.close();


In the above code, every C in the set of C's is updated, even though the collection was never modified in any way.

Thanks for your time and insights.

Gregg

A.hbm.xml
<hibernate-mapping>
<class name="A" table="A" >
<id name="APK" column="APK" type="long">
<generator class="edit.services.db.hibernate.KeyGenerator"/>
</id>
<set name="Cs" table="C" inverse="true" cascade="all" >
<key column="AFK"/>
<one-to-many class="C"/>
</set>
</hibernate-mapping>

C.hbm.xml
<hibernate-mapping>
<class name="C" table="C" >
<id name="CPK" column="CPK" type="long">
<generator class="edit.services.db.hibernate.KeyGenerator"/>
</id>
<many-to-one
name="A"
column="AFK
class="A"
cascade="none"
/>
</hibernate-mapping>


Top
 Profile  
 
 Post subject:
PostPosted: Fri Aug 05, 2005 3:11 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
This usually mean that your equals/hashcode methods are incorrect

seb


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.