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