views:

504

answers:

1

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!

+1  A: 

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.

Chaos