Medioman92
Medioman92

Reputation: 571

Hibernate one to many relationship removing child object

i have a simple one to many mapping in my project...let's suppose that i have 1 father object and 3 child objects stored in my DB. the problem occurs when i load the father object and change the number of sons (for example removing one of them). When i try to update the father object, the son that is no longer in the child's set it's still on the DB. Is there a way to delete the unwanted child without have to manually proceed?

Upvotes: 3

Views: 2379

Answers (1)

Crferreira
Crferreira

Reputation: 1238

You can use the attribute orphanRemoval=true on the @OneToMany annotation.

Upvotes: 2

Related Questions