I have 2 classes User and Login bind by a one-to-one bidirectionnal association.
I retrieve the login's informations and i write something like that :
Code:
Login l = new Login();
l.setId("toto");
l.setPwd("toto");
...
User user = new User();
user.setName("John Doe");
...
user.setLogin(l);
...
session.save(user);
The mapping file is as follow (excerpt):
Code:
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd">
<hibernate-mapping>
<class name="com.cfort.utilisateur.Login" table="login">
<id name="identifiant" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<property name="motPasse" type="string" length="20"/>
<one-to-one name="internaute" class="com.cfort.utilisateur.Internaute"/>
</class>
<class name="com.cfort.utilisateur.Adresse" table="adresse">
<id name="identifiant" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<property name="rue" type="string" length="100"/>
<property name="codePostal" type="string" length="5"/>
<property name="ville" type="string" length="40"/>
<property name="email" type="string" length="40"/>
<property name="telephone" type="string" length="20"/>
<property name="departement" type="string" length="30"/>
<property name="region" type="string" length="30"/>
<property name="fax" type="string" length="20"/>
</class>
<class name="com.cfort.utilisateur.Internaute" table="internaute" discriminator-value="I">
<id name="identifiant" column="identifiant" type="string" length="20">
<generator class="assigned"/>
</id>
<discriminator column="type" type="character"/>
<property name="nbPoints"/>
<property name="nbPointsAcheter"/>
<!-- Relation avec la classe Login : bidirectionnelle -->
<one-to-one name="login" class="com.cfort.utilisateur.Login"/>
<!-- Relation avec la classe Adresse : monodirectionnelle -->
<one-to-one name="adresse" class="com.cfort.utilisateur.Adresse"/>
</class>
</hibernate-mapping>
It works but only the user's informations are saved in the DB.
Is it normal or do i have to save the login before.
I believed that when we save an object, hibernate automatically saves all the objects binded to it!!!!!!
Thanks