-->
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: A BIG question...
PostPosted: Wed Mar 23, 2005 12:38 pm 
Newbie

Joined: Mon Mar 21, 2005 9:34 am
Posts: 1
Dear hibernate lovers...

I'm testing hibernate 3 and i'm lost...
I've a relation one to many bidirectional

Map1
Code:
<class name="Role">
      <id name="idRole"/>
      
      <property name="nom"/>
      <property name="lire"/>
      <property name="ecrire"/>
      
      <set name="utilisateurs" inverse="true">
         <key column="idRole_fk"/>
         <one-to-many class="Utilisateur"/>
      </set>
   </class>


Map2
Code:
<class name="Utilisateur">
      <id name="idUtilisateur"/>
      
      <property name="nom"/>
      <property name="prenom"/>
      <property name="login"/>
      <property name="password"/>
      
      <many-to-one name="role" column="idRole_fk" not-null="true"/>
   </class>


Class1
Code:
private String idUtilisateur;
    private String nom;
    private String prenom;
    private String login;
    private String password;
    private Role role;


Class2
Code:
private String idRole;
    private String nom;
    private String lire;
    private String ecrire;
    private Set utilisateurs;


Test code
Code:
Utilisateur u1 = (Utilisateur) session.load(Utilisateur.class, "xxx");
            Role r1 = u1.getRole();
           
            Set s1 = r1.getUtilisateurs();
            System.out.println(s1.size());
           
            //---------------------------------------
           
            Role r2 = (Role) session.load(Role.class, r1.getNom());
            Set s2 = r2.getUtilisateurs();
            System.out.println(s2.size());
           
            //---------------------------------------
           
            Query query = session.createQuery("select c from Role as c");
           
            for (Iterator it = query.iterate(); it.hasNext();)
            {
                Role r3 = (Role) it.next();
                Set s3 = r3.getUtilisateurs();
                System.out.println(s3.size());
            }


Console output
Code:
Hibernate: select utilisateu0_.idRole_fk as idRole6___, utilisateu0_.idUtilisateur as idUtilis1___, utilisateu0_.idUtilisateur as idUtilis1_0_, utilisateu0_.nom as nom7_0_, utilisateu0_.prenom as prenom7_0_, utilisateu0_.login as login7_0_, utilisateu0_.password as password7_0_, utilisateu0_.idRole_fk as idRole6_7_0_ from Utilisateur utilisateu0_ where utilisateu0_.idRole_fk=?
2
Hibernate: select utilisateu0_.idRole_fk as idRole6___, utilisateu0_.idUtilisateur as idUtilis1___, utilisateu0_.idUtilisateur as idUtilis1_0_, utilisateu0_.nom as nom7_0_, utilisateu0_.prenom as prenom7_0_, utilisateu0_.login as login7_0_, utilisateu0_.password as password7_0_, utilisateu0_.idRole_fk as idRole6_7_0_ from Utilisateur utilisateu0_ where utilisateu0_.idRole_fk=?
0
Hibernate: select role0_.idRole as col_0_0_ from Role role0_
2


WHY the first and second request are the same but the result not...
Is session.load() different?? and why

Tankxx for your lights...


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.