-->
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.  [ 3 posts ] 
Author Message
 Post subject: Many-to-Many and join
PostPosted: Wed Aug 18, 2004 11:55 am 
Beginner
Beginner

Joined: Mon Sep 15, 2003 9:10 am
Posts: 43
Hibernate version:2.4

2 Pojos :

Code:
public class Utilisateur extends BaseObject{

    private Long id;
    private Set roles=new HashSet();
   
    /**
      * @hibernate.set                    lazy="true" table="rolesutilisateurs" cascade="save-update"
      * @hibernate.collection-key           column="id_utilisateur"
      * @hibernate.collection-many-to-many  class="org.astre.sig.modele.Role" column="id_role"
      *       
      */
     public Set getRoles() {
         return this.roles;
     }
   
     public void setRoles(Set roles) {
         this.roles = roles;
     }
}


public class Role extends BaseObject{
   
    /** identifier field */
    private Long id;

    /** nullable persistent field */
    private String libelle;

    /** full constructor */
    public Role(String libelle) {
        this.libelle = libelle;
    }

    /** default constructor */
    public Role() {
    }

   /**
     * @hibernate.id  generator-class="native"  unsaved-value="0"
     */
    public Long getId() {
        return this.id;
    }

    public void setId(Long id) {
        this.id = id;
    }

   /**
     * @hibernate.property
     */
    public String getLibelle() {
        return this.libelle;
    }

    public void setLibelle(String libelle) {
        this.libelle = libelle;
    }
}


Code between sessionFactory.openSession() and session.close():

Code:
session.find("from Role");


Result :

Code:
Hibernate: select roles0_.id_role as id_role__, roles0_.id_utilisateur as id_utili1___ from rolesutilisateurs roles0_ where roles0_.id_utilisateur=?


But i just want the list of role not a join with utilisateurs.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 18, 2004 12:07 pm 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
show generated role mapping file

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject: Mapping file
PostPosted: Wed Aug 18, 2004 12:32 pm 
Beginner
Beginner

Joined: Mon Sep 15, 2003 9:10 am
Posts: 43
<hibernate-mapping>
<class
name="org.astre.sig.modele.Role"
table="roles"
dynamic-update="false"
dynamic-insert="false"
>

<jcs-cache usage="read-write" />

<id
name="id"
column="id"
type="java.lang.Long"
unsaved-value="0"
>
<generator class="native">
</generator>
</id>

<property
name="libelle"
type="java.lang.String"
update="true"
insert="true"
access="property"
column="libelle"
/>

<!--
To add non XDoclet property mappings, create a file named
hibernate-properties-Role.xml
containing the additional properties and place it in your merge dir.
-->

</class>

</hibernate-mapping>


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.