Bonjour,
Je début tout juste dans NHibernate, et j'ai un petit problème dans l'écriture du mapping.
J'ai une classe Etudiant, une classe Livre et une classe Personne.
Un étudiant hérie de personne et possède une association "SesLivres" qui renvoie la collection des livres empruntés par l'étudiant.
Voici mon fichier de mapping :
Code:
<class name="WindowsApplication2.Personne, WindowsApplication2" table="Personne">
<id name="ID" type="Int32" column="IDPersonne">
<generator class="identity"></generator>
</id>
<property name="Nom" column="nom" type="String"></property>
<property name="Prenom" column="prenom" type="String"></property>
<property name="Age" column="age" type="Int32"></property>
<joined-subclass name="WindowsApplication2.Etudiant, WindowsApplication2" table="Etudiant">
<key column="IDPersonne" foreign-key="IDEtudiant"></key>
<property name="Code" column="code" type="String"></property>
<set lazy="true" name="SesLivres">
<key column="codeEtudiant" foreign-key="IDEtudiant"></key>
<one-to-many class="WindowsApplication2.Livre, WindowsApplication2"></one-to-many>
</set>
</joined-subclass>
</class>
<class name="WindowsApplication2.Livre, WindowsApplication2" table="Livre">
<id name="ID" type="Int32" column="IDLivre">
<generator class="identity"></generator>
</id>
<property name="Nom" column="nom" type="String"></property>
<property name="Code" column="code" type="Int32"></property>
</class>
Comme vous le voyez j'utilse la technique du "une table par classe".
Contenu de la table Personne : IDPersonne, nom, prenom, age
Contenu de la table Etudiant : IDEtudiant, code , IDPersonne
Conteun de la table Livre : IDLivre, code, IDEtudiant
Le problème c'est que quand il enregistre un étudiant, il utilise l'ID de la Personne dans la table Livre, et pas l'ID de l'étudiant généré dynamiquement (je veux pouvoir séparer les deux !)
Comment faire en sorte de séparer l'ID de la Personne et l'ID de l'Etudiant, pour que quand on enregistre un Etudiant, les livres qui lui sont liés prennent bien l'ID de cet étudiant, et pas l'ID hérité de la Personne ?
(c'est clair ? lol)
Merci ...