How to enforce orphan deletion on a ManyToOne relationship
@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 relationsh开发者_开发问答ip, 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?
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
精彩评论