Reputation: 532
I m currently reading : Hibernate Documentation Chapter 10.11 Trying to figure out how hibernate's methods work .
Let's assume i have a parent object Cat with the following mapping to it's associated Kittens children.
<set cascade="all" name="Kittens" inverse="true">
<key>
<column name="KittenName" length="36" not-null="true" />
</key>
<one-to-many class=".......model.Kittens" />
</set>
With this association i would expect that whenever I load() a Cat in my app , delete it's Kittens collection and saveOrUpdate() OR attachDirty() it back in the db during the same Hibernate session the associated Kittens collection would be deleted but it's not . The only changes that take effect during flushing are modifications on the Cat (parent) object .
Note : I am not trying to cascade the deletion of the parent object but cascade the modifications on it .
Am I missing something here ?
Upvotes: 0
Views: 97
Reputation: 17435
To also remove all kittens when a cat is removed; you will need to cascade style delete-orphan
. This is not included by default in all
.
So
<set cascade="all, delete-orphan" name="Kittens" inverse="true">
should do the trick.
On the other hand, if you try to delete the kittens directly in the db, the actual objects will still be referenced in your set. As soon as you flush your cat, hibernate will simply recreate the kittens.
Upvotes: 1