yvkk
yvkk

Reputation:

Deleting thing "A" in hibernate does not update objects with collections of "A"

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?

Upvotes: 0

Views: 556

Answers (1)

Mark
Mark

Reputation: 29119

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.

Upvotes: 1

Related Questions