0

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?

Stjoan
  • 29
  • 2

2 Answers2

1

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

Stjoan
  • 29
  • 2
0

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
  • 1,768
  • 4
  • 16
  • 31
  • As per documentation "DELETE_ORPHAN applies only to @OneToMany associations", so it is not a solution here. – Stjoan Jan 20 '10 at 07:36