-->
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.  [ 2 posts ] 
Author Message
 Post subject: Recheche, polymorphisme, propriété introuvable
PostPosted: Mon Mar 26, 2007 9:21 am 
Newbie

Joined: Mon Mar 26, 2007 9:10 am
Posts: 1
Location: France
j'utilise NHibernate 1.0.x assimilable a Hibernate 2.1.

Classes :
Code:
public class Personne {
  public int Id;
  public string Nom;
}

public class Individu extends Personne {
  public string Prenom;
}


Mapping :
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0" >
   <class name="Personne" table="T_PERSONNE_PERS" >
      <id name="Id" column="PERS_ID" type="Int32">
         <generator class="sequence">
            <param name="sequence">GEN_PERS_ID</param>
         </generator>
      </id>
      <property name="Nom" column="PERS_NOM" type="String" />
      <joined-subclass name="Individu" table="T_INDIVIDU_IND" >
         <key column="PERS_ID"/>
         <property name="Prenom" column="IND_FIRST_NAME" />
      </joined-subclass>
   </class>
</hibernate-mapping>


et le code appelant
Code:
//...
ICriteria vCriteria = Session.CreateCriteria(typeof(Personne));
vCriteria.Add(Expression.Or(Expression.Eq("Nom", "toto"), Expression.Eq("prenom", "titi")));
IList vResultats = vCriteria.List();
//...


Avec Session.CreateCriteria() sur la classe Personne, il me dit qu'il ne connait pas la pas la propriété Prenom.
Pourtant (grâce au polymorphisme), si je lui demande que des Personnes avec Nom = "toto", il me retournera aussi bien les personnes que les individus ayant ce nom.
Pourquoi un test "polymorphique" n'a pas l'air fonctionné ?
Est-ce possible ?
Comment faire ?

Merci d'avance.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Mar 27, 2007 7:45 am 
Expert
Expert

Joined: Thu Sep 04, 2003 8:23 am
Posts: 368
C'est la même chose que dans ton langage de programmation.

La propriété prénom n'existe pas sur personne donc tu ne peux faire un getPrenom.

Si tu veux faire un critère sur prénom, il faut le faire sur des individus.

Les requêtes polymorphiques comme tu le veux semblent avoir été implémentées dans hibernate 3.0 mais je ne trouve pas d'info sur comment c'est réellement implémenté :

http://forum.hibernate.org/viewtopic.ph ... phic+query

http://opensource.atlassian.com/project ... owse/HB-33

_________________
Seb
(Please don't forget to give credits if you found this answer useful :)


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

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.