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

后端 未结 2 415
情话喂你
情话喂你 2021-01-03 01:21

I am having problems removing another entity through cascade delete-orphan. It works when I clear the associated set collection, but not when I make the set collection null.

2条回答
  •  渐次进展
    2021-01-03 01:42

    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.

提交回复
热议问题