Hi all,
I have a query regarding the saving mapped object in hibernate.
I have this mapping in my application
Entity A hbm contents
---------------------------------
<set name="bContents" table="B" lazy="true" inverse="true" cascade="all-delete-orphan" sort="unsorted" >
<key column="B_ID"></key>
<one-to-many class="com.xyz.B"/>
</set>
Entity B hbm contents
---------------------------------
<many-to-one name="a" class="com.xyz.A" cascade="none"
outer-join="auto" update="true" insert="true" column="A_ID" not-null="true"/>
<set name="cContents" table="C" lazy="true" inverse="true" cascade="all-delete-orphan" sort="unsorted">
<key column="B_ID"></key>
<one-to-many class="com.xyz.C"/>
</set>
Entity C hbm contents
---------------------------------
<many-to-one name="b" class="com.xyz.B" cascade="none" outer-join="auto" update="true" insert="true"
column="B_ID" not-null="true"/>
Currrently, in my application each of these entities are saved seperately. We are not saving the relationships while saving the contents like
A a = getA();
B b = new B();
save(b)
a.getBContents().add(b); // This is not done
save(a);// This is not done
I am not sure why we are getting inconsistent entries in collections above bContents and cContents when we load the object a or b.
Can somebody tell me whats da best practice to save such mapped relationships.??
Thanks in advance,
|