Hi, here is my pb that i can't understand :
2 class : contact and fonction with a n-n mapping that doesn't working
Can anyone help ?
My Fonction mapping :
Code:
<hibernate-mapping>
<class
name="framework.entreprise.Fonction"
table="fonctions"
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"
access="property"
column="libelle"
/>
<property
name="abreviation"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="abreviation"
/>
<set
name="contacts"
table="fonctionscontacts"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
column="id_fonction"
>
</key>
<many-to-many
class="framework.entreprise.Contact"
column="id_contact"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Fonction.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
My Contact mapping : Code:
<hibernate-mapping>
<class
name="framework.entreprise.Contact"
table="contacts"
dynamic-update="false"
dynamic-insert="false"
>
<id
name="id"
column="id"
type="long"
unsaved-value="-1"
>
<generator class="native">
</generator>
</id>
<property
name="email"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="email"
/>
<property
name="fax"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="fax"
/>
<property
name="nom"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="nom"
/>
<property
name="prenom"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="prenom"
/>
<property
name="telephone"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="telephone"
/>
<property
name="portable"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="portable"
/>
<many-to-one
name="entreprise"
class="framework.entreprise.Entreprise"
cascade="none"
outer-join="auto"
update="true"
insert="true"
access="property"
column="id_entreprise"
/>
<set
name="offres"
lazy="false"
inverse="true"
cascade="all-delete-orphan"
sort="unsorted"
>
<key
column="id_contact"
>
</key>
<one-to-many
class="framework.entreprise.OffreFret"
/>
</set>
<property
name="identifiantInstranet"
type="int"
update="true"
insert="true"
access="property"
column="identifiantInstranet"
/>
<set
name="fonctions"
table="fonctionscontacts"
lazy="true"
inverse="true"
cascade="none"
sort="unsorted"
>
<key
column="id_contact"
>
</key>
<many-to-many
class="framework.entreprise.Fonction"
column="id_fonction"
outer-join="auto"
/>
</set>
<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Contact.xml
containing the additional properties and place it in your merge dir.
-->
</class>
</hibernate-mapping>
My code : Code:
Contact c=new Contact();
c.setId(-1);
c.setNom("Fabien");
session.save(c);
session.flush();
if (c.getFonctions()==null) c.setFonctions(new HashSet());
Fonction f=new Fonction();
f.setId(-1);
f.setLibelle("fonction");
session.save(f);
session.flush();
c.getFonctions().add(f);
session.save(c);
session.flush();
The result :Code:
Hibernate: insert into contacts (email, fax, nom, prenom, telephone, portable, id_entreprise, identifiantInstranet) values (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: insert into fonctions (libelle, abreviation) values (?, ?)
Why my table fonctionscontacts is empty ?
Thanks,
Fabien.