0

I am trying to delete all the referenced entity in a collection of a parent entity by setting null on the collection.

For eg :

A is the parent class having one-to-many relation with class B.

Class A {
private Set<B> setB = new HashSet<B>();
}

The mapping is as follows :
<set name="setB " table="B" cascade="save-update" inverse="true">
    <key column="FKey"></key>
    <one-to-many class="B" />
</set>

a.setB(null);//a is persistent instance of A

The above call to set the collection as null is not deleting the entries in B. Has this anything to do with inverse = true. Is it illegal to delete the child entities this way?

user2599052
  • 1,056
  • 3
  • 12
  • 27

1 Answers1

0

What about a.getB().clear();?

Volker Seibt
  • 1,479
  • 16
  • 19
  • This will work if cascade is set to delete-orphan. But I wanted to know if it is possible to delete by setting to null. – user2599052 Sep 18 '13 at 04:07
  • This was a retorical question - you should use `clear()`. See accepted answer from http://stackoverflow.com/questions/14686595/hibernate-onetomany-remove-child-from-list-when-updating-parent, I can not explain it better. – Volker Seibt Sep 18 '13 at 19:25