Sorry :-(
Hibernate version : hibernate-2.1.2
Mapping document :
"The parent" :
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="framework.entreprise.ModeleRecherche"
table="modelesrecherche"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>
<property
name="libelle"
type="java.lang.String"
update="true"
insert="true"
column="libelle"
/>
<many-to-one
name="utilisateur"
class="framework.entreprise.Utilisateur"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="id_utilisateur"
/>
<set
name="zones"
lazy="true"
inverse="false"
cascade="save-update"
sort="unsorted"
>
<key
column="id_recherche"
/>
<one-to-many
class="framework.entreprise.ZoneModeleRecherche"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ModeleRecherche.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
"The child":Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD 2.0//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class
name="framework.entreprise.ModeleRecherche"
table="modelesrecherche"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>
<property
name="libelle"
type="java.lang.String"
update="true"
insert="true"
column="libelle"
/>
<many-to-one
name="utilisateur"
class="framework.entreprise.Utilisateur"
cascade="none"
outer-join="auto"
update="true"
insert="true"
column="id_utilisateur"
/>
<set
name="zones"
lazy="true"
inverse="false"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="id_recherche"
/>
<one-to-many
class="framework.entreprise.ZoneModeleRecherche"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-ModeleRecherche.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
Sample code :
[code]
tx= s.beginTransaction();
ModeleRecherche m = new ModeleRecherche();
ZoneModeleRecherche z1 = new ZoneModeleRecherche();
ZoneModeleRecherche z2 = new ZoneModeleRecherche();
m.setLibelle("Mon modele de test");
m.setZones(new HashSet());
s.save(z1);
m.getZones().add(z1);
s.save(z2);
m.getZones().add(z2);
s.save(m);
s.flush();
m.getZones().removeAll(m.getZones());
ZoneModeleRecherche z3=new ZoneModeleRecherche();
s.save(z3);
m.getZones().add(z3);
s.save(m);
s.flush();
tx.commit();
[code]
Database : MySQL - 4.0.12