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

JPA Java Discussion :

Jointure JPA pour récupérer nom article


Sujet :

JPA Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut Jointure JPA pour récupérer nom article
    bonjour j'aimerais faire une jointure pour recuprer le nom de l'article qui corespond a l'id de la table reparation

    voici mes entitie

    article :
    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package entity;
     
    import java.io.Serializable;
    import java.math.BigDecimal;
    import java.util.Collection;
    import javax.persistence.Basic;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.Table;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author Coshom
     */
    @Entity
    @Table(name = "article")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Article.findAll", query = "SELECT a FROM Article a"),
        @NamedQuery(name = "Article.findByNumCodeBarre", query = "SELECT a FROM Article a WHERE a.numCodeBarre = :numCodeBarre"),
        @NamedQuery(name = "Article.findByNom", query = "SELECT a FROM Article a WHERE a.nom = :nom"),
        @NamedQuery(name = "Article.findByDescription", query = "SELECT a FROM Article a WHERE a.description = :description"),
        @NamedQuery(name = "Article.findByCategorie", query = "SELECT a FROM Article a WHERE a.categorie = :categorie"),
        @NamedQuery(name = "Article.findByPrix", query = "SELECT a FROM Article a WHERE a.prix = :prix"),
        @NamedQuery(name = "Article.findByMarque", query = "SELECT a FROM Article a WHERE a.marque = :marque"),
        @NamedQuery(name = "Article.findByNbCote", query = "SELECT a FROM Article a WHERE a.nbCote = :nbCote"),
        @NamedQuery(name = "Article.findByTotalCote", query = "SELECT a FROM Article a WHERE a.totalCote = :totalCote"),
        @NamedQuery(name = "Article.findByQuantite", query = "SELECT a FROM Article a WHERE a.quantite = :quantite"),
        @NamedQuery(name = "Article.findByQuantiteMax", query = "SELECT a FROM Article a WHERE a.quantiteMax = :quantiteMax"),
        @NamedQuery(name = "Article.findByQuantiteMin", query = "SELECT a FROM Article a WHERE a.quantiteMin = :quantiteMin"),
        @NamedQuery(name = "Article.findByGarantie", query = "SELECT a FROM Article a WHERE a.garantie = :garantie"),
        @NamedQuery(name = "Article.findByDisponibilite", query = "SELECT a FROM Article a WHERE a.disponibilite = :disponibilite"),
        @NamedQuery(name = "Article.findByUrl", query = "SELECT a FROM Article a WHERE a.url = :url")})
    public class Article implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 50)
        @Column(name = "num_code_barre_")
        private String numCodeBarre;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 30)
        @Column(name = "nom")
        private String nom;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 255)
        @Column(name = "description")
        private String description;
        @Basic(optional = false)
        @NotNull
        @Column(name = "categorie")
        private int categorie;
        // @Max(value=?)  @Min(value=?)//if you know range of your decimal fields consider using these annotations to enforce field validation
        @Basic(optional = false)
        @NotNull
        @Column(name = "prix")
        private BigDecimal prix;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 30)
        @Column(name = "marque")
        private String marque;
        @Basic(optional = false)
        @NotNull
        @Column(name = "nbCote")
        private int nbCote;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 10)
        @Column(name = "total_cote")
        private String totalCote;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite")
        private int quantite;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite_max")
        private int quantiteMax;
        @Basic(optional = false)
        @NotNull
        @Column(name = "quantite_min")
        private int quantiteMin;
        @Basic(optional = false)
        @NotNull
        @Column(name = "garantie")
        private int garantie;
        @Basic(optional = false)
        @NotNull
        @Column(name = "disponibilite")
        private char disponibilite;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 255)
        @Column(name = "url")
        private String url;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Vente> venteCollection;
        @OneToMany(mappedBy = "numCodeBarre")
        private Collection<Reparation> reparationCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Support> supportCollection;
        @OneToMany(cascade = CascadeType.ALL, mappedBy = "numCodeBarre")
        private Collection<Commentaire> commentaireCollection;
     
        public Article() {
        }
     
        public Article(String numCodeBarre) {
            this.numCodeBarre = numCodeBarre;
        }
     
        public Article(String numCodeBarre, String nom, String description, int categorie, BigDecimal prix, String marque, int nbCote, String totalCote, int quantite, int quantiteMax, int quantiteMin, int garantie, char disponibilite, String url) {
            this.numCodeBarre = numCodeBarre;
            this.nom = nom;
            this.description = description;
            this.categorie = categorie;
            this.prix = prix;
            this.marque = marque;
            this.nbCote = nbCote;
            this.totalCote = totalCote;
            this.quantite = quantite;
            this.quantiteMax = quantiteMax;
            this.quantiteMin = quantiteMin;
            this.garantie = garantie;
            this.disponibilite = disponibilite;
            this.url = url;
        }
     
        public String getNumCodeBarre() {
            return numCodeBarre;
        }
     
        public void setNumCodeBarre(String numCodeBarre) {
            this.numCodeBarre = numCodeBarre;
        }
     
        public String getNom() {
            return nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public int getCategorie() {
            return categorie;
        }
     
        public void setCategorie(int categorie) {
            this.categorie = categorie;
        }
     
        public BigDecimal getPrix() {
            return prix;
        }
     
        public void setPrix(BigDecimal prix) {
            this.prix = prix;
        }
     
        public String getMarque() {
            return marque;
        }
     
        public void setMarque(String marque) {
            this.marque = marque;
        }
     
        public int getNbCote() {
            return nbCote;
        }
     
        public void setNbCote(int nbCote) {
            this.nbCote = nbCote;
        }
     
        public String getTotalCote() {
            return totalCote;
        }
     
        public void setTotalCote(String totalCote) {
            this.totalCote = totalCote;
        }
     
        public int getQuantite() {
            return quantite;
        }
     
        public void setQuantite(int quantite) {
            this.quantite = quantite;
        }
     
        public int getQuantiteMax() {
            return quantiteMax;
        }
     
        public void setQuantiteMax(int quantiteMax) {
            this.quantiteMax = quantiteMax;
        }
     
        public int getQuantiteMin() {
            return quantiteMin;
        }
     
        public void setQuantiteMin(int quantiteMin) {
            this.quantiteMin = quantiteMin;
        }
     
        public int getGarantie() {
            return garantie;
        }
     
        public void setGarantie(int garantie) {
            this.garantie = garantie;
        }
     
        public char getDisponibilite() {
            return disponibilite;
        }
     
        public void setDisponibilite(char disponibilite) {
            this.disponibilite = disponibilite;
        }
     
        public String getUrl() {
            return url;
        }
     
        public void setUrl(String url) {
            this.url = url;
        }
     
        @XmlTransient
        public Collection<Vente> getVenteCollection() {
            return venteCollection;
        }
     
        public void setVenteCollection(Collection<Vente> venteCollection) {
            this.venteCollection = venteCollection;
        }
     
        @XmlTransient
        public Collection<Reparation> getReparationCollection() {
            return reparationCollection;
        }
     
        public void setReparationCollection(Collection<Reparation> reparationCollection) {
            this.reparationCollection = reparationCollection;
        }
     
        @XmlTransient
        public Collection<Support> getSupportCollection() {
            return supportCollection;
        }
     
        public void setSupportCollection(Collection<Support> supportCollection) {
            this.supportCollection = supportCollection;
        }
     
        @XmlTransient
        public Collection<Commentaire> getCommentaireCollection() {
            return commentaireCollection;
        }
     
        public void setCommentaireCollection(Collection<Commentaire> commentaireCollection) {
            this.commentaireCollection = commentaireCollection;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (numCodeBarre != null ? numCodeBarre.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Article)) {
                return false;
            }
            Article other = (Article) object;
            if ((this.numCodeBarre == null && other.numCodeBarre != null) || (this.numCodeBarre != null && !this.numCodeBarre.equals(other.numCodeBarre))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.Article[ numCodeBarre=" + numCodeBarre + " ]";
        }
     
    }

    entity reperation

    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
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package entity;
     
    import java.io.Serializable;
    import java.util.Date;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.Table;
    import javax.persistence.Temporal;
    import javax.persistence.TemporalType;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;
     
    /**
     *
     * @author Coshom
     */
    @Entity
    @Table(name = "reparation")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Reparation.findAll", query = "SELECT r FROM Reparation r"),
        @NamedQuery(name = "Reparation.findByEtat", query = "SELECT r FROM Reparation r WHERE r.etat = :etat"),
        @NamedQuery(name = "Reparation.findByNumReparation", query = "SELECT r FROM Reparation r WHERE r.numReparation = :numReparation"),
        @NamedQuery(name = "Reparation.findByDescription", query = "SELECT r FROM Reparation r WHERE r.description = :description"),
        @NamedQuery(name = "Reparation.findByDateDebut", query = "SELECT r FROM Reparation r WHERE r.dateDebut = :dateDebut"),
        @NamedQuery(name = "Reparation.findnum_client", query = "SELECT r FROM Reparation r WHERE r.numClient = :numclient "),
        @NamedQuery(name = "Reparation.findByDateFinPrevue", query = "SELECT r FROM Reparation r WHERE r.dateFinPrevue = :dateFinPrevue")})
    public class Reparation implements Serializable {
        private static final long serialVersionUID = 1L;
        @Basic(optional = false)
        @NotNull
        @Column(name = "etat_")
        private char etat;
        @Id
        @Basic(optional = false)
        @NotNull
        @Column(name = "num_reparation")
        private Integer numReparation;
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 255)
        @Column(name = "description")
        private String description;
        @Basic(optional = false)
        @NotNull
        @Column(name = "date_debut")
        @Temporal(TemporalType.DATE)
        private Date dateDebut;
        @Basic(optional = false)
        @NotNull
        @Column(name = "date_fin_prevue")
        @Temporal(TemporalType.DATE)
        private Date dateFinPrevue;
        @JoinColumn(name = "num_code_barre_", referencedColumnName = "num_code_barre_")
        @ManyToOne
        private Article numCodeBarre;
        @JoinColumn(name = "num_client", referencedColumnName = "num_client")
        @ManyToOne(optional = false)
        private Membre numClient;
     
        public Reparation() {
        }
     
        public Reparation(Integer numReparation) {
            this.numReparation = numReparation;
        }
     
        public Reparation(Integer numReparation, char etat, String description, Date dateDebut, Date dateFinPrevue) {
            this.numReparation = numReparation;
            this.etat = etat;
            this.description = description;
            this.dateDebut = dateDebut;
            this.dateFinPrevue = dateFinPrevue;
        }
     
        public char getEtat() {
            return etat;
        }
     
        public void setEtat(char etat) {
            this.etat = etat;
        }
     
        public Integer getNumReparation() {
            return numReparation;
        }
     
        public void setNumReparation(Integer numReparation) {
            this.numReparation = numReparation;
        }
     
        public String getDescription() {
            return description;
        }
     
        public void setDescription(String description) {
            this.description = description;
        }
     
        public Date getDateDebut() {
            return dateDebut;
        }
     
        public void setDateDebut(Date dateDebut) {
            this.dateDebut = dateDebut;
        }
     
        public Date getDateFinPrevue() {
            return dateFinPrevue;
        }
     
        public void setDateFinPrevue(Date dateFinPrevue) {
            this.dateFinPrevue = dateFinPrevue;
        }
     
        public Article getNumCodeBarre() {
            return numCodeBarre;
        }
     
        public void setNumCodeBarre(Article numCodeBarre) {
            this.numCodeBarre = numCodeBarre;
        }
     
        public Membre getNumClient() {
            return numClient;
        }
     
        public void setNumClient(Membre numClient) {
            this.numClient = numClient;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (numReparation != null ? numReparation.hashCode() : 0);
            return hash;
        }
     
        @Override
        public boolean equals(Object object) {
            // TODO: Warning - this method won't work in the case the id fields are not set
            if (!(object instanceof Reparation)) {
                return false;
            }
            Reparation other = (Reparation) object;
            if ((this.numReparation == null && other.numReparation != null) || (this.numReparation != null && !this.numReparation.equals(other.numReparation))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "entity.Reparation[ numReparation=" + numReparation + " ]";
        }
     
    }
    pour l'instant dans la reparation facade j'ai :


    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     
       public List<Reparation> MesReparation (Membre membre) {
     
             Query query = em.createNamedQuery("Reparation.findnum_client");
                   query.setParameter("numclient", membre);  
           return  query.getResultList();      
        }

  2. #2
    Membre éclairé
    Profil pro
    Inscrit en
    Octobre 2009
    Messages
    226
    Détails du profil
    Informations personnelles :
    Localisation : Belgique

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Par défaut
    reponce :

    ${reparation.numCodeBarre.nom}

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [XL-2007] script pour récupérer nom de fichier et le mettre dans excel
    Par demon21 dans le forum Macros et VBA Excel
    Réponses: 2
    Dernier message: 19/01/2011, 21h05
  2. Code vba pour récupérer nom du PC
    Par majudis dans le forum VBA Access
    Réponses: 1
    Dernier message: 04/10/2010, 20h53
  3. Fonction pour récupérer nom d'un fichier
    Par fabsb dans le forum Langage
    Réponses: 2
    Dernier message: 03/05/2009, 15h40
  4. Requête pour récupérer le nom des champs
    Par legillou dans le forum JDBC
    Réponses: 1
    Dernier message: 08/02/2006, 17h09

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