Reputation: 493
I have a hibernate bean called Property which has a type and a value. If type is a certain class (EntityValue) then value is a link to BaseEntity. BaseEntity has a @OneToMany @CascadeType.ALL List properties.
In order to safely delete a BaseEntity I will need to make sure it's not part of an EntityValue in any other BaseEntityS. Even if I can come up with the hql to figure out which BaseEntityS reference a given BaseEntity, can I delete a Property from it's collection, will it's linking table entry be deleted?
Thanks!
Upvotes: 0
Views: 955
Reputation: 7178
I think what you're looking for is the annotation :
@Cascade({org.hibernate.annotations.CascadeType.DELETE_ORPHAN})
This will have the effect of removing the other side of a one-to-many when you remove the parent entity.
Upvotes: 1