views:

108

answers:

1

Say you had a Cat, with Kittens. Then you you did a delete() on a kitten that belongs to a Cat. The Cat object still has a reference to the deleted kitten, until the session closes.

What's an elegant way to avoid this situation?

+1  A: 

You should delete the Kitten from the collection of its associated Cat then store the updated Cat. In your hibernate configuration set cascade to "all,delete-orphan" for Cat and the Kitten will be removed from the persisted collection.

Mark