i am using the built hibernate 2.1.2.
I have a association parent-child.
class com.Parent mapping:
Code:
<bag
name="childs"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
>
<key
column="parent_fk"
/>
<one-to-many
class="com.Child"
/>
</bag>
and,
class com.Child mapping:
Code:
<many-to-one
name="parent"
class="com.Parent"
cascade="save-update"
outer-join="auto"
update="true"
insert="true"
column="parent_fk"
not-null="true"
/>
Using hibernate 2.1.2 and mysql.
The java code:
Code:
... get child from database
...
Parent oldParent = child.getParent();
Parent newParent = ... from database;
oldParent.getChilds().remove(child);
newParent.getChilds().add(child);
child.setParent(newParent);
...
save the child.
The above code failed with "deleted object would be re-saved by cascade".
But, if I change the mapping from "all-delete-orphan" to "all" in com.Parent mapping.
Everything works.
Why??