I am getting an error:
Don't change the reference to a collection with cascade="all-delete-orphan"
while trying the following operation:
beginTx();
Parent parent = new Parent();
Child child = new Child();
parent.addChild(child);
getSession().save(parent);
commitTx();
closeSession();
beginTx();
//id is the primary key
child.setID(null);
getSession().update(child);
commitTx();
closeSession();
Parent and child are related by one-to-many
with cascade = 'all-delete-orphan
'.
class Parent {
Set child;
}
<set name="child" table="Child" cascade="all-delete-orphan" inverse="true">
<key column="FK"></key>
<one-to-many class="Child"/>
</set>
Any idea why this exception is being thrown? Why is setting null on the primary key causing this exception even though the entity is in detached state ?
child.setID(null);
? – ArachnechildCategory
? and what are you trying to achieve by callingchild.setID(null);
? – Cryotherapychild.setID(null);
are you attempting to remove a specific entry in the Child Set ? – Cryotherapy