0
@ManyToOne(fetch = LAZY)
@JoinColumn(name = COL_GROUP_ID, nullable = false, insertable = false, updatable = false, referencedColumnName = COL_ID)
@OnDelete(action = CASCADE)
@Cascade(value = DELETE_ORPHAN)
private Group group;

How to enforce orphan deletion on a ManyToOne relationship, the above code snippet worked for us in Hibernate 3.3.x, but post migration to 3.6.5.Final it shows up as a WARNING in the code. is there a equivalent flag like orphanRemoval = true which is applied on a @OneToMany notation?

Joe
  • 12,573
  • 26
  • 77
  • 140
  • 1
    Is there an API? Do you have the link? Have you [searched SO](http://stackoverflow.com/questions/306144/jpa-cascadetype-all-does-not-delete-orphans) or [google](http://www.google.com/search?hl=en&safe=off&client=firefox-a&hs=PLT&rls=org.mozilla%3Aen-US%3Aofficial&q=hibernate+3.6.5+cascade+delete+manytoone&aq=f&aqi=&aql=&oq=)? – Atreys Jun 18 '11 at 04:21
  • @Atreys - The above link talks about support for orphanRemoval on a @OneToMany annotation. We have some legacy code (from Hibernate 3.3.x) which we are trying to migrate and I didn't see any support for orphanRemoval on a @ManyToOne annotation. Hence the question – Joe Jun 20 '11 at 15:29

1 Answers1

0

You can not apply ORPHAN_REMOVAL to MANY_TO_ONE side.

Suppose you have an entity City which has @OneToMany Citizen and on the other side you have @ManyToOne City in Citizen entity. In your scenario removing one citizen will lead to removing the whole city, thus ORPHAN_REMOVAL is only applicable to XXX_TO_Many side

Nick
  • 61
  • 1
  • 9