I tried a different strategy :
with a cascade mode sets to "all-delete-orphan"
and the following code
Code:
Session session = sf.openSession();
session.load(parent);
parent.getKids().clear();
session.save(parent);
session.flush();
session.connection().commit();
Mapping:
Code:
<class name="Parent"
table="PARENT"
dynamic-update="false"
dynamic-insert="false"
discriminator-value="null" >
<set name="kids"
lazy="true"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted">
<key column="PARENT_ID" />
<one-to-many class="Kid" />
</set>
</class>
<class name="Kid"
table="KID"
dynamic-update="false"
dynamic-insert="false" >
<many-to-one name="Parent"
class="Parent"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="PARENT_ID"
not-null="true" />
</class>
I get only one select of parent, one select for all kids and one delete for all kids. It is much better, but still Hibernate has to load all the Kids instances in session. I don't think there is any way to avoid that.