views:

37

answers:

2

I have two entities, lets call them A and B, which have a ManyToOne mapping to another entity, say C

So I typically have something like this:

a1->c

a2->c

b1->c

Lots of A's and B's pointing to the same C.

How do I get Hibernate to remove c when I remove the last a and b?

A: 

There is an attribute delete-orphan that you can use when mapping the many-to-one relation, this should do the work for you.

for more info. I advise visiting they documentation online about the cascading operations.

Omar Al Kababji
As per documentation "DELETE_ORPHAN applies only to @OneToMany associations", so it is not a solution here.
Stjoan
A: 

It seems that JPA/Hibernate does not support this. Which is really bad.

Stjoan

related questions