remove collection with delete-orphan not work with null assignment? :(

点点圈 提交于 2019-11-30 14:41:10

I think its because hibernate uses its own collection implementations (which is why the docs say you MUST declare collections as interfaces, not implementations), and the collection implementations obey the semantics of you transitive persistence settings. So, when you do

cats.getBla().clear()

the getBla() part is the hibernate collection implementation, which knows to remove the children from the session when clear() is called.

When you do

cats.setBla(null);

you haven't removed the collection, you have changed the parent's reference to the collection to null. The collection probably still exists in the session.

In the version 5 of Hibernate the problem is very similar but an exception is thrown instead: "A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance". To tackle that I had to switch from null values to empty collections.

The issue in Hibernate is posted here: https://hibernate.atlassian.net/browse/HHH-9940

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