Bonjour,
Je possède les 3 tables suivantes
Utilisateurid_user
firstname
lastname
....
rightid_user
id_stis
right
stisid_stis
namestis
....
Hibernate tools ma générer les fichiers hbm et class ci dessous :
user.java
Code:
/**
* User generated by hbm2java
*/
public class User implements java.io.Serializable {
private int idUser;
private String login;
private String pass;
private String email;
private String firstname;
private String lastname;
private String organization;
private String phone;
private String type;
private Boolean upgrade;
private Set rights = new HashSet(0);
public User() {
}
public User(int idUser) {
this.idUser = idUser;
}
public User(int idUser, String login, String pass, String email,
String firstname, String lastname, String organization,
String phone, String type, Boolean upgrade, Set rights) {
this.idUser = idUser;
this.login = login;
this.pass = pass;
this.email = email;
this.firstname = firstname;
this.lastname = lastname;
this.organization = organization;
this.phone = phone;
this.type = type;
this.upgrade = upgrade;
this.rights = rights;
}
// getter et setter
}
user.hbm.xml
Code:
<!-- Generated 16 mars 2011 18:06:39 by Hibernate Tools 3.4.0.CR1 -->
<hibernate-mapping package="model">
<class catalog="public" name="User" table="utilisateur">
<id name="idUser" type="int">
<column name="id_user" not-null="true"/>
<generator class="increment"/>
</id>
<property generated="never" lazy="false" name="login" type="string">
<column name="login"/>
</property>
<property generated="never" lazy="false" name="pass" type="string">
<column name="pass"/>
</property>
<property generated="never" lazy="false" name="email" type="string">
<column name="email"/>
</property>
<property generated="never" lazy="false" name="firstname" type="string">
<column name="firstname"/>
</property>
<property generated="never" lazy="false" name="lastname" type="string">
<column name="lastname"/>
</property>
<property generated="never" lazy="false" name="organization" type="string">
<column name="organization"/>
</property>
<property generated="never" lazy="false" name="phone" type="string">
<column name="phone"/>
</property>
<property generated="never" lazy="false" name="type" type="string">
<column name="type"/>
</property>
<property generated="never" lazy="false" name="upgrade" type="java.lang.Boolean">
<column name="upgrade"/>
</property>
<set fetch="select" inverse="true" lazy="true" name="rights"
sort="unsorted" table="right">
<key>
<column name="id_user" not-null="true"/>
</key>
<one-to-many class="model.Right"/>
</set>
</class>
</hibernate-mapping>
stis.java
Code:
/**
* Stis generated by hbm2java
*/
public class Stis implements java.io.Serializable {
private int idStis;
private String rdm;
private String rd;
private String cdm;
private String mapRdmCdm;
private String mapCdmPm;
private String icdm;
private String pm;
private String gui;
private String nameStis;
private String visibility;
private Set rights = new HashSet(0);
public Stis() {
}
public Stis(int idStis) {
this.idStis = idStis;
}
public Stis(int idStis, String rdm, String rd, String cdm,
String mapRdmCdm, String mapCdmPm, String icdm, String pm,
String gui, String nameStis, String visibility, Set rights) {
this.idStis = idStis;
this.rdm = rdm;
this.rd = rd;
this.cdm = cdm;
this.mapRdmCdm = mapRdmCdm;
this.mapCdmPm = mapCdmPm;
this.icdm = icdm;
this.pm = pm;
this.gui = gui;
this.nameStis = nameStis;
this.visibility = visibility;
this.rights = rights;
}
getter et setter
}
stis.hbm.xml
Code:
<hibernate-mapping package="model">
<class catalog="public" name="Stis" table="stis">
<id name="idStis" type="int">
<column name="id_stis"/>
<generator class="increment"/>
</id>
<property generated="never" lazy="false" name="rdm" type="string">
<column name="rdm"/>
</property>
<property generated="never" lazy="false" name="rd" type="string">
<column name="rd"/>
</property>
<property generated="never" lazy="false" name="cdm" type="string">
<column name="cdm"/>
</property>
<property generated="never" lazy="false" name="mapRdmCdm" type="string">
<column name="map_rdm_cdm"/>
</property>
<property generated="never" lazy="false" name="mapCdmPm" type="string">
<column name="map_cdm_pm"/>
</property>
<property generated="never" lazy="false" name="icdm" type="string">
<column name="icdm"/>
</property>
<property generated="never" lazy="false" name="pm" type="string">
<column name="pm"/>
</property>
<property generated="never" lazy="false" name="gui" type="string">
<column name="gui"/>
</property>
<property generated="never" lazy="false" name="nameStis" type="string">
<column name="name_stis"/>
</property>
<property generated="never" lazy="false" name="visibility" type="string">
<column name="visibility"/>
</property>
<set fetch="select" inverse="true" lazy="true" name="rights"
sort="unsorted" table="right">
<key>
<column name="id_stis" not-null="true"/>
</key>
<one-to-many class="model.Right"/>
</set>
</class>
</hibernate-mapping>
right.java
Code:
public class Right implements java.io.Serializable {
private RightId id;
private Stis stis;
private User user;
public Right() {
}
public Right(RightId id, Stis stis, User user) {
this.id = id;
this.stis = stis;
this.user = user;
}
//getter et setter}
right.hbm.xml
Code:
hibernate-mapping package="model">
<class catalog="public" name="Right" table="right">
<composite-id class="model.RightId"
mapped="false" name="id" unsaved-value="undefined">
<key-property name="right" type="string">
<column name="right"/>
</key-property>
<key-property name="idUser" type="long">
<column name="id_user"/>
</key-property>
<key-property name="idStis" type="long">
<column name="id_stis"/>
</key-property>
</composite-id>
<many-to-one class="model.Stis" fetch="select"
insert="false" name="stis" update="false">
<column name="id_stis" not-null="true"/>
</many-to-one>
<many-to-one class="model.User" fetch="select"
insert="false" name="user" update="false">
<column name="id_user" not-null="true"/>
</many-to-one>
</class>
</hibernate-mapping>
Comment faire pour effectuer un enregistrement d'un utilisateur avec un right lecture sur un stis ?
je suppose qu'il faut utiliser les hashset??