-->
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: enregistrement dans clé composé
PostPosted: Thu Mar 17, 2011 11:19 am 
Newbie

Joined: Thu Mar 17, 2011 11:03 am
Posts: 1
Bonjour,

Je possède les 3 tables suivantes

Utilisateur
id_user
firstname
lastname
....

right
id_user
id_stis
right

stis
id_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??


Top
 Profile  
 
 Post subject: Re: enregistrement dans clé composé
PostPosted: Fri Apr 01, 2011 2:51 am 
Newbie

Joined: Thu Mar 31, 2011 4:37 am
Posts: 11
Non tu ne dois aps utiliser les hashsets.

Tu crées un nouveau objet utilisateur et un nouvel objet right avec l'identifiant de l'utilisateur et du stis.
Tu saves ceux-ci et le tour est joué.


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.