Collection.clear() will delete children whenever Session flushes.
What about OneToOne? Setting to null is not a correct way. No clear() method for OneToOne exists.
Table_A has a column (not its PK!) that OneToOne references Table_B.
I wonder if Hib works as expected in my case?
My Cascading options are set to “all,delete-orphan”.
Table_A @OneToOne Table_B
Table_B @OneToMany Table_C
Now it looks like Table_A . getTable_B . getTable_C_Collection()
Suppose there are elements in Table_C collection.
What I expect from Hibernate: if I set Table_B link to null, then
all Table_C collection elements MUST BE DELETED.
It does not happen. They become ORPHANED !
Hibernate’s support for cascading actions can be a bit quirky at times. If you find that you cannot get the desired behavior out-of-the-box, you can implement a Hibernate Interceptor or a Hibernate event listener. It’s actually pretty easy to do ether, and the effort is worth it (your main code remains clean).
In this case, you probably want to implement a PostUpdateEventListener, or a PreUpdateEventListener.