IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Hibernate Java Discussion :

One to many sur un Id composé


Sujet :

Hibernate Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    F2S
    F2S est déconnecté
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Par défaut One to many sur un Id composé
    Bonjour à tous,

    voilà mon soucis...

    J'ai un bean qui a un id composé comme suit :
    package com.fnac.piloting.treasury.bean.batch;

    import com.fnac.piloting.treasury.bean.AbstractBusinessBean;

    /**
    * RubricTicketAdmin : rubric parameters to feed rubrics for treasury day
    *
    * @author
    *
    * @hibernate.class table="RUBRIC_TICKET_ADMIN"
    */
    public class RubricTicketAdmin extends AbstractBusinessBean {
    /** RubricTicketAdminId */
    private RubricTicketAdminId rubricTicketAdminId;
    /** administrative operation code */
    private String _adminOperation;
    /** payment mode */
    private String _paymentMode;


    /**
    * @return the sequence
    *
    * @return value
    *
    * @hibernate.property column="ADMIN_OPERATION"
    */
    public String getAdminOperation() {
    return _adminOperation;
    }
    /**
    * @param operation the _adminOperation to set
    */
    public void setAdminOperation(String operation) {
    _adminOperation = operation;
    }

    /**
    * @return the sequence
    *
    * @return value
    *
    * @hibernate.property column="PAYMENT_MODE"
    */
    public String getPaymentMode() {
    return _paymentMode;
    }
    /**
    * @param mode the _paymentMode to set
    */
    public void setPaymentMode(String mode) {
    _paymentMode = mode;
    }

    /**
    * return the property value
    *
    * @return value
    *
    * @hibernate.id generator-class="assigned"
    */
    public RubricTicketAdminId getRubricTicketAdminId() {
    return rubricTicketAdminId;
    }
    /**
    * @param rubricTicketAdminId the rubricTicketAdminId to set
    */
    public void setRubricTicketAdminId(RubricTicketAdminId rubricTicketAdminId) {
    this.rubricTicketAdminId = rubricTicketAdminId;
    }

    }

    la classe Id est :
    package com.fnac.piloting.treasury.bean.batch;

    import java.io.Serializable;

    import com.fnac.piloting.treasury.bean.Rubric;

    /**
    * Id class for RubricTicketAdmin, made because Hibernate needs an id
    *
    * @author
    */
    public class RubricTicketAdminId implements Serializable {
    /** RubricId */
    private Rubric rubric;
    /** Sequence */
    private Integer sequence;



    /**
    * @return the rubric
    * @hibernate.many-to-one
    * column="RUBRIC_ID"
    * not-null="true"
    */
    public Rubric getRubric() {
    return rubric;
    }
    /**
    * @param rubric the rubric to set
    */
    public void setRubric(Rubric rubric) {
    this.rubric = rubric;
    }
    /**
    * @return the sequence
    *
    * @return value
    *
    * @hibernate.property column="RUBRIC_SEQUENCE"
    */
    public Integer getSequence() {
    return sequence;
    }
    /**
    * @param sequence the sequence to set
    */
    public void setSequence(Integer sequence) {
    this.sequence = sequence;
    }
    /* (non-Javadoc)
    * @see java.lang.Object#hashCode()
    */
    public int hashCode() {
    final int PRIME = 31;
    int result = 1;
    result = PRIME * result + ((rubric == null) ? 0 : rubric.hashCode());
    result = PRIME * result + ((sequence == null) ? 0 : sequence.hashCode());
    return result;
    }
    /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
    public boolean equals(Object obj) {
    if (this == obj)
    return true;
    if (obj == null)
    return false;
    if (getClass() != obj.getClass())
    return false;
    final RubricTicketAdminId other = (RubricTicketAdminId) obj;
    if (rubric == null) {
    if (other.rubric != null)
    return false;
    } else if (!rubric.equals(other.rubric))
    return false;
    if (sequence == null) {
    if (other.sequence != null)
    return false;
    } else if (!sequence.equals(other.sequence))
    return false;
    return true;
    }

    }


    maintenant je voudrai faire une liaison "on-to-many" avec une atre classe, voilà le code :
    /*
    * Last modified by: $Author: mmeyer $
    *
    * Copyright (c) 2004 Fnac S.A.
    */

    package com.fnac.piloting.treasury.bean;

    import java.util.Collections;
    import java.util.Date;
    import java.util.Set;


    /**
    * Category to classify treasury amounts (mostly a payment mean)
    *
    * @author Frédéric Esnault
    *
    * @hibernate.class table="RUBRIC"
    */
    public class Rubric extends AbstractBusinessBean {
    /** "Cheque" rubric code */
    public static final String RUBRIC_CHEQUE = "CHEQUE";
    /** debit type */
    public static final String DEBIT_TYPE = "D";
    /** credit type */
    public static final String CREDIT_TYPE = "C";
    /** "CA Net des remises" rubric code */
    public static final String RUBRIC_CANETR = "CANETR";
    /** "Clients arrhes reçus" rubric code */
    public static final String RUBRIC_CLARRE = "CLARRE";
    /** "Clients arrhes déduits" rubric code */
    public static final String RUBRIC_CLARDE = "CLARDE";
    /** "Ventes différées perçues" rubric code */
    public static final String RUBRIC_VDIFFP = "VDIFFP";
    /** "Fonds de caisse fermeture" rubric code */
    public static final String RUBRIC_FONDSF = "FONDSF";
    /** "Fonds de caisse ouverture" rubric code */
    public static final String RUBRIC_FONDSO = "FONDSO";
    /** "Ventes différées éditées" rubric code */
    public static final String RUBRIC_VDIFFE = "VDIFFE";
    /** "2e déclic" rubric code */
    public static final String RUBRIC_2EDECL = "2EDECL";
    /** "Régularisations" rubric code */
    public static final String RUBRIC_REGUL = "REGUL";
    /** "Ventes Clients Administratifs" rubric code */
    public static final String RUBRIC_VADMIN = "VADMIN";
    /** technical key to identify the object */
    private Integer _rubricId;
    /** sequence number giving the presentation order */
    private Integer _sequence;
    /** source param */
    // private RubricSourceParam _rubricSourceParam;
    /** set of RubricAccount instances */
    private Set _rubricAccounts = Collections.EMPTY_SET;
    /** short code to identiy the rubric */
    private String _code;
    /** long label explaining the rubric */
    private String _label;
    /** type of rubric : debit (D) or credit (C) */
    private String _type;
    /** flag to specify if rubric is editable */
    private boolean _editable;
    /** sequence number giving the output entry order */
    private Integer _outputEntrySequence;
    /** End date for rubric, to stop treatment in batch */
    private Date _endDate;
    /** RubricTicketAdmin */
    private Set rubricTicketAdmin = Collections.EMPTY_SET;
    /** is source hardcoded */
    private boolean _hardCoded;


    /** country - multiple country problematic */
    //private Country _country;
    private EnseignePays _cPy;

    /**
    * Constructor
    */
    public Rubric() {
    super();
    }

    /**
    * sets the code
    *
    * @param string the code
    */
    public void setCode(String string) {
    _code = string;
    }

    /**
    * returns the code
    *
    * @return the code
    *
    * @hibernate.property column="CODE"
    */
    public String getCode() {
    return _code;
    }

    /**
    * sets the editable flag
    *
    * @param b a boolean value
    */
    public void setEditable(boolean b) {
    _editable = b;
    }

    /**
    * returns if rubric is editable
    *
    * @return true if editable
    *
    * @hibernate.property column="EDITABLE" type="yes_no"
    */
    public boolean isEditable() {
    return _editable;
    }

    /**
    * sets the label
    *
    * @param string the label
    */
    public void setLabel(String string) {
    _label = string;
    }

    /**
    * returns the label
    *
    * @return the label
    *
    * @hibernate.property column="LABEL"
    */
    public String getLabel() {
    return _label;
    }

    /**
    * set the associated rubric accounts
    *
    * @param set set
    */
    public void setRubricAccounts(Set set) {
    _rubricAccounts = set;
    }

    /**
    * returns the associated rubric accounts
    *
    * @return the rubric accounts
    *
    * @hibernate.set lazy="true" cascade="all-delete-orphan"
    * @hibernate.collection-key column="RUBRIC_ID"
    * @hibernate.collection-one-to-many
    * class="com.fnac.piloting.treasury.bean.RubricAccount"
    */
    public Set getRubricAccounts() {
    return _rubricAccounts;
    }

    /**
    * sets the id (key)
    *
    * @param integer the id
    */
    public void setRubricId(Integer integer) {
    _rubricId = integer;
    }

    /**
    * returns the id (key)
    *
    * @return value
    *
    * @hibernate.id generator-class="sequence" unsaved-value="null"
    * column="RUBRIC_ID"
    * @hibernate.generator-param name="sequence" value="TREASURY_SEQUENCE"
    *
    * */
    public Integer getRubricId() {
    return _rubricId;
    }

    /**
    * @return the rubricTicketAdmin
    *
    * @hibernate.set lazy="true" cascade="all-delete-orphan"
    * @hibernate.collection-key column="RUBRIC_ID"
    * @hibernate.collection-one-to-many
    * class="com.fnac.piloting.treasury.bean.batch.RubricTicketAdmin"
    */
    public Set getRubricTicketAdmin() {
    return rubricTicketAdmin;
    }

    /**
    * @param rubricTicketAdmin the rubricTicketAdmin to set
    */
    public void setRubricTicketAdmin(Set rubricTicketAdmins) {
    rubricTicketAdmin = rubricTicketAdmins;
    }
    /**
    * set the sequence
    *
    * @param integer the sequence
    */
    public void setSequence(Integer integer) {
    _sequence = integer;
    }

    /**
    * returns the sequence
    *
    * @return the sequence
    *
    * @hibernate.property column="SEQUENCE"
    */
    public Integer getSequence() {
    return _sequence;
    }

    /**
    * sets the type
    *
    * @param string the type
    */
    public void setType(String string) {
    _type = string;
    }

    /**
    * returns the type
    *
    * @return the type
    *
    * @hibernate.property column="TYPE"
    */
    public String getType() {
    return _type;
    }

    /**
    * @see java.lang.Object#equals(java.lang.Object)
    */
    public boolean equals(Object obj) {
    if (!(obj instanceof Rubric)) {
    return false;
    }
    return getRubricId() != null
    && getRubricId().equals(((Rubric) obj).getRubricId());
    }

    /**
    * @see java.lang.Object#hashCode()
    */
    public int hashCode() {
    if (getRubricId() == null) {
    return -1;
    }
    return getRubricId().intValue();
    }


    /**
    * returns the sequence
    *
    * @return the sequence
    *
    * @hibernate.property column="OUTPUT_ENTRY_SEQUENCE"
    */
    public Integer getOutputEntrySequence() {
    return _outputEntrySequence;
    }

    /**
    * set the sequence
    *
    * @param integer the sequence
    */
    public void setOutputEntrySequence(Integer integer) {
    _outputEntrySequence = integer;
    }

    /**
    * returns the endDate
    *
    * @return the code
    *
    * @hibernate.property column="END_DATE"
    */
    public Date getEndDate() {
    return _endDate;
    }
    /**
    * @param endDate The endDate to set.
    */
    public void setEndDate(Date endDate) {
    _endDate = endDate;
    }

    /**
    * @return the enseigne pays
    * @hibernate.many-to-one
    * column="C_PY"
    * not-null="true"
    */
    public EnseignePays getCPy() {
    return _cPy;
    }
    /**
    * @param cpy the enseigne pays to set
    */
    public void setCPy(EnseignePays cPy) {
    _cPy = cPy;
    }

    /**
    * set the property value
    *
    * @param b value
    */
    public void setHardCoded(boolean b) {
    _hardCoded = b;
    }

    /**
    * return the property value
    *
    * @return value
    *
    * @hibernate.property column="HARD_CODED" type="yes_no"
    */
    public boolean isHardCoded() {
    return _hardCoded;
    }

    }

    mon problème vient certainement du mapping... en faite qd je créer ma rubric il ne crée pas de rubricTicketAdmin...

    est ce que quelqu'un peut m'aider....

  2. #2
    Membre Expert
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Par défaut
    Les balises CODE c'est bien... tu peux les rajouter ?

  3. #3
    F2S
    F2S est déconnecté
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Par défaut
    Bonjour à tous,

    voilà mon soucis...

    J'ai un bean qui a un id composé comme suit :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
     
    public class RubricTicketAdmin extends AbstractBusinessBean {
     
    /** RubricTicketAdminId */
    private RubricTicketAdminId rubricTicketAdminId;
    /** administrative operation code */
    private String _adminOperation;
    /** payment mode */
    private String _paymentMode;
     
     
    /**
    *
    * @return value
    *
    * @hibernate.property column="ADMIN_OPERATION"
    */
    public String getAdminOperation() {
    return _adminOperation;
    }
    /**
    * @param operation the _adminOperation to set
    */
    public void setAdminOperation(String operation) {
    _adminOperation = operation;
    }
     
    /**
    *
    * @return value
    *
    * @hibernate.property column="PAYMENT_MODE"
    */
    public String getPaymentMode() {
    return _paymentMode;
    }
     
    /**
    * @param mode the _paymentMode to set
    */
    public void setPaymentMode(String mode) {
    _paymentMode = mode;
    }
     
    /**
    * return the property value
    *
    * @return value
    *
    * @hibernate.id generator-class="assigned"
    */
     
    public RubricTicketAdminId getRubricTicketAdminId() {
    return rubricTicketAdminId;
    }
     
    /**
    * @param rubricTicketAdminId the rubricTicketAdminId to set
    */
    public void setRubricTicketAdminId(RubricTicketAdminId rubricTicketAdminId) {
    this.rubricTicketAdminId = rubricTicketAdminId;
    }
     
    }
    la classe Id est :
    package com.fnac.piloting.treasury.bean.batch;

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
     
     
    public class RubricTicketAdminId implements Serializable {
    /** RubricId */
    private Rubric rubric;
    /** Sequence */
    private Integer sequence;
     
     
    /**
    * @return the rubric
    * @hibernate.many-to-one 
    * column="RUBRIC_ID"
    * not-null="true"
    */
    public Rubric getRubric() {
    return rubric;
    }
     
    /**
    * @param rubric the rubric to set
    */
    public void setRubric(Rubric rubric) {
    this.rubric = rubric;
    }
     
    /**
    *
    * @return value
    *
    * @hibernate.property column="RUBRIC_SEQUENCE"
    */
    public Integer getSequence() {
    return sequence;
    }
     
    /**
    * @param sequence the sequence to set
    */
    public void setSequence(Integer sequence) {
    this.sequence = sequence;
    }
    /* (non-Javadoc)
    * @see java.lang.Object#hashCode()
    */
    public int hashCode() {
    ....
    }
    /* (non-Javadoc)
    * @see java.lang.Object#equals(java.lang.Object)
    */
    public boolean equals(Object obj) {
    .....
    }
     
    }
    maintenant je voudrai faire une liaison "on-to-many" avec une atre classe, voilà le code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
     
    public class Rubric extends AbstractBusinessBean {
     
    /** RubricTicketAdmin */
    private Set rubricTicketAdmin = Collections.EMPTY_SET;
     
    /**
    * Constructor
    */
    public Rubric() {
    super();
    }
     
     
    /**
    * @return the rubricTicketAdmin
    * 
    * @hibernate.set lazy="true" cascade="all-delete-orphan"
    * @hibernate.collection-key column="RUBRIC_ID"
    * @hibernate.collection-one-to-many
    * class="com.fnac.piloting.treasury.bean.batch.RubricTicketAdmin"
    */
    public Set getRubricTicketAdmin() {
    return rubricTicketAdmin;
    }
     
    /**
    * @param rubricTicketAdmin the rubricTicketAdmin to set
    */
    public void setRubricTicketAdmin(Set rubricTicketAdmins) {
    rubricTicketAdmin = rubricTicketAdmins;
    } 
    }
    mon problème vient certainement du mapping... en faite qd je créer ma rubric il ne crée pas de rubricTicketAdmin...

    est ce que quelqu'un peut m'aide

  4. #4
    Membre Expert
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Par défaut
    Tu es sûr que tu as bien des RubricTicketAdmin dans ton Set avant le save ?

  5. #5
    F2S
    F2S est déconnecté
    Membre confirmé
    Profil pro
    Inscrit en
    Avril 2006
    Messages
    139
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Avril 2006
    Messages : 139
    Par défaut
    oui voilà le code

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    RubricTicketAdminId rubricTicketAdminId = new RubricTicketAdminId();
                           
                
         Set tickets = new ArraySet();
         tickets.add(rubricTicket);
         rubric.setRubricTicketAdmin(tickets);
         rubricTicket.setRubricTicketAdminId(rubricTicketAdminId);
         rubricTicketAdminId.setRubric(rubric);
         rubricTicketAdminId.setSequence(new Integer (sequenceTicket + 1));
                
          // create rubric
         dao.create(rubric);

  6. #6
    Membre Expert
    Homme Profil pro
    Directeur technique
    Inscrit en
    Janvier 2007
    Messages
    1 348
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 48
    Localisation : France, Paris (Île de France)

    Informations professionnelles :
    Activité : Directeur technique

    Informations forums :
    Inscription : Janvier 2007
    Messages : 1 348
    Par défaut
    et fait quoi ?

Discussions similaires

  1. relation one-to-many mais pas sur l'ID
    Par youkoun dans le forum Hibernate
    Réponses: 2
    Dernier message: 07/06/2010, 17h35
  2. Réponses: 3
    Dernier message: 05/04/2010, 14h42
  3. Problème de delete sur one-to-many avec une cascade
    Par Theoden dans le forum Hibernate
    Réponses: 2
    Dernier message: 02/01/2009, 17h43
  4. requete hql sur association one to many avec inner class
    Par austin P. dans le forum Hibernate
    Réponses: 1
    Dernier message: 07/06/2007, 11h56
  5. [EJB2.1 Entity] [CMR] Relation One to Many
    Par hamed dans le forum Java EE
    Réponses: 2
    Dernier message: 31/12/2003, 14h26

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo