-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Hibernate et l'héritage
PostPosted: Wed Mar 08, 2006 6:11 am 
Beginner
Beginner

Joined: Tue Mar 07, 2006 8:50 am
Posts: 20
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 ...


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.