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.