Hi guys
I'm using
Hibernate version: 3.0.5. I'm using the version tag in all hbm.xml files. I have a question about chapter 21.2. Bidirectional one-to-many in the hibernate reference.
The Code:
Java:
Code:
Parent p = (Parent) session.load(Parent.class, pid);
Child c = new Child();
p.getChildren().add(c);
c.setParent(p);
session.save(c);
session.flush();
Using a bag, only one SQL INSERT would be issued (What i've expected):Parent:
Code:
<bag name="children" inverse="true">
<key column="PARENT_FK_ID"/>
<one-to-many class="Child"/>
</bag>
Child:
Code:
<many-to-one name="parent" foreign-key="FK_CHILD_TO_PARENT" not-null="true">
<column name="PARENT_FK_ID" length="40"/>
</many-to-one>
Using a set, it's different behaviour. It is inserting the child and updating the Parent Parent:
Code:
<set name="children" inverse="true">
<key column="PARENT_FK_ID"/>
<one-to-many class="Child"/>
</set>
Child:
Code:
<many-to-one name="parent" foreign-key="FK_CHILD_TO_PARENT" not-null="true">
<column name="PARENT_FK_ID" length="40"/>
</many-to-one>
Question
Has anyone an idea why it's updating the parent in the set example?
How can I avoid the update on the parent?
TIA and best regards
Dominic