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. Let me explain in detail. The config snippet:
<class name="com.sample.CategoriesDefault" table="cats">
<id name="id" column="id" type="string" length="40" access="property">
<generator class="assigned" />
</id>
<version name="version" column="objVrs" unsaved-value="negative"/>
<set name="bla" lazy="false" cascade="all-delete-orphan" inverse="true">
<key column="idCats" not-null="true"/>
<one-to-many class="com.sample.BLA"/>
</set>
<class name="com.sample.BLA" table="blaTEST">
<id name="id" column="id" type="string" length="40" access="property">
<generator class="assigned" />
</id>
<version name="version" column="objVrs" unsaved-value="negative"/>
<property name="bla" type="string" column="bla"/>
<many-to-one name="parent" class="com.sample.CategoriesDefault" column="idCats" not-null="true"/>
</class>
My sample code:
Categories cats = new CategoriesDefault();
final Set<BLA> col = new HashSet<BLA>();
col.add(new BLA(cats));
cats.setBla(col);
cats.saveOrupdate(); // will update/insert it in the db.
The following works correctly, that is: all the collection items are all moved from the db.
cats.getBla().clear();
cats.saveOrUpdate();
I think this works as the PersistSet of Hibernate is marked as dirty when calling this method.
The following however doesn't work the same as above like I would want/expect.
cats.setBla(null);
cats.saveOrUpdate();
If I reload the cats item from the db, it still contains the BLA items and no delete statement is generated by Hibernate :(.. Why not??... or is this a bug ? I am using 3.6.0.Final.