JPA 2 / Hibernate orphan removal still not working with @OneToMany?

强颜欢笑 提交于 2019-11-30 18:08:54

Honestly, I don't know why, but if you add CascadeType.PERSIST (or better CascadeType.ALL) to your @OneToMany relationship in Provider entity it will work as expected.

Probably the Hibernate documentation is lacking in this little detail.

update EclipseLink 2.5.1 with JPA2 does not seem to have this issue

2nd update

In Section 2.9, Entity Relationships, the JPA 2.1 spec says: "If the entity being orphaned is a detached, new, or removed entity, the semantics of orphanRemoval do not apply."

I don't know if your related entities are detached, but if yes then it's not a bug :)

dsrajput

I am also getting the issue stated. Though it has been deprecated, below use is working fine with orphan removal:

@org.hibernate.annotations.Cascade(org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!