When I call clear() method on a mapped collection (many-to-one unidirectional association) with cascade=all, children are not remove from the collection in the database. When I set cascade=all-delete-orphan, children are removed from the collection, and also deleted in the database, fine. However, I just want to delete the association, not the children item (that's why I try to use cascade=all). Any idea to that problem ?
Java code
Code:
session = getSession();
tx = session.beginTransaction();
Un un = (Un)session.get(Un.class, new Long(i));// => two elements in the collection
un.getDeux().clear();// => no updates !
tx.commit();
MappingCode:
<class name="Un" table="UN">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="code" column="CODE"/>
<list name="deux" cascade="all" inverse="false">
<key column="UN_ID"/>
<list-index column="POSITION"/>
<one-to-many class="Deux"/>
</list>
</class>
<class name="Deux" table="DEUX">
<id name="id" column="ID">
<generator class="increment"/>
</id>
<property name="code" column="CODE"/>
</class>