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

Développement Web en Java Discussion :

Problème en createquery()


Sujet :

Développement Web en Java

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2013
    Messages : 11
    Par défaut Problème en createquery()
    Salut à tous,

    J'ai deux tables : table d'intervention et la table agentministere. Chaque intervention a un clé étrangère qui est idagent(clé primaire pour table agentministere). Notre application demande d'afficher les interventions du agent qui a authentifié par nom et mot de passe. J'ai essayé ce requête mais elle ne marche pas
    code :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
     Query query =
                 getEntityManager().createQuery("SELECT intervention FROM Intervention as intervention join intervention.idagent as idagent WHERE idagent.nomAgent = :nom and idagent.prenomAgent= :prenom" );
     
                 query.setParameter("nom",nom);
     
                 query.setParameter("prenom",prenom);
                 interventions=(List<Intervention>)  query. getResultList();
    Merci pour tout

  2. #2
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Bonjour,
    Peut on voir le code des Entités Intervention et Agent?

  3. #3
    Membre averti
    Homme Profil pro
    Étudiant
    Inscrit en
    Août 2013
    Messages
    11
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : Tunisie

    Informations professionnelles :
    Activité : Étudiant
    Secteur : Enseignement

    Informations forums :
    Inscription : Août 2013
    Messages : 11
    Par défaut
    Entité Agentministere :
    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
    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
    package jpa;
     
    import java.io.Serializable;
    import java.math.BigInteger;
    import java.util.Collection;
    import java.util.Date;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.SequenceGenerator;
    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;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author Akrem
     */
    @Entity
    @Table(name = "AGENTMINISTERE")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Agentministere.findAll", query = "SELECT a FROM Agentministere a"),
        @NamedQuery(name = "Agentministere.findByNomAgent", query = "SELECT a FROM Agentministere a WHERE a.nomAgent = :nomAgent"),
        @NamedQuery(name = "Agentministere.findByPrenomAgent", query = "SELECT a FROM Agentministere a WHERE a.prenomAgent = :prenomAgent"),
        @NamedQuery(name = "Agentministere.findByTelAgent", query = "SELECT a FROM Agentministere a WHERE a.telAgent = :telAgent"),
        @NamedQuery(name = "Agentministere.findByAdresse", query = "SELECT a FROM Agentministere a WHERE a.adresse = :adresse"),
        @NamedQuery(name = "Agentministere.findByEmail", query = "SELECT a FROM Agentministere a WHERE a.email = :email"),
        @NamedQuery(name = "Agentministere.findByDateNaiss", query = "SELECT a FROM Agentministere a WHERE a.dateNaiss = :dateNaiss"),
        @NamedQuery(name = "Agentministere.findByDateEmbauche", query = "SELECT a FROM Agentministere a WHERE a.dateEmbauche = :dateEmbauche"),
        @NamedQuery(name = "Agentministere.findByFonction", query = "SELECT a FROM Agentministere a WHERE a.fonction = :fonction"),
        @NamedQuery(name = "Agentministere.findByDateAffectation", query = "SELECT a FROM Agentministere a WHERE a.dateAffectation = :dateAffectation"),
        @NamedQuery(name = "Agentministere.findByPosteInterne", query = "SELECT a FROM Agentministere a WHERE a.posteInterne = :posteInterne"),
        @NamedQuery(name = "Agentministere.findByIdagent", query = "SELECT a FROM Agentministere a WHERE a.idagent = :idagent")})
    public class Agentministere implements Serializable {
        private static final long serialVersionUID = 1L;
        @Size(max = 30)
        @Column(name = "NOM_AGENT")
        private String nomAgent;
        @Size(max = 35)
        @Column(name = "PRENOM_AGENT")
        private String prenomAgent;
        @Column(name = "TEL_AGENT")
        private BigInteger telAgent;
        @Size(max = 100)
        @Column(name = "ADRESSE")
        private String adresse;
        // @Pattern(regexp="[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?", message="Invalid email")//if the field contains email address consider using this annotation to enforce field validation
        @Size(max = 40)
        @Column(name = "EMAIL")
        private String email;
        @Column(name = "DATE_NAISS")
        @Temporal(TemporalType.TIMESTAMP)
        private Date dateNaiss;
        @Column(name = "DATE_EMBAUCHE")
        @Temporal(TemporalType.TIMESTAMP)
        private Date dateEmbauche;
        @Size(max = 30)
        @Column(name = "FONCTION")
        private String fonction;
        @Column(name = "DATE_AFFECTATION")
        @Temporal(TemporalType.TIMESTAMP)
        private Date dateAffectation;
        @Size(max = 30)
        @Column(name = "POSTE_INTERNE")
        private String posteInterne;
        @Id
       @GeneratedValue(strategy= GenerationType.IDENTITY,generator="seq_agent")
        @SequenceGenerator(name="seq_agent",sequenceName="seq_agent", allocationSize=1)
     
        @Basic(optional = false)
        @NotNull
        @Size(min = 1, max = 30)
        @Column(name = "IDAGENT")
        private String idagent;
        @JoinColumn(name = "ID_DEPT", referencedColumnName = "ID_DEPT")
        @ManyToOne
        private Departement idDept;
        @OneToMany(mappedBy = "idagent")
        private Collection<Intervention> interventionCollection;
     
        public Agentministere() {
        }
     
        public Agentministere(String idagent) {
            this.idagent = idagent;
        }
     
        public String getNomAgent() {
            return nomAgent;
        }
     
        public void setNomAgent(String nomAgent) {
            this.nomAgent = nomAgent;
        }
     
        public String getPrenomAgent() {
            return prenomAgent;
        }
     
        public void setPrenomAgent(String prenomAgent) {
            this.prenomAgent = prenomAgent;
        }
     
        public BigInteger getTelAgent() {
            return telAgent;
        }
     
        public void setTelAgent(BigInteger telAgent) {
            this.telAgent = telAgent;
        }
     
        public String getAdresse() {
            return adresse;
        }
     
        public void setAdresse(String adresse) {
            this.adresse = adresse;
        }
     
        public String getEmail() {
            return email;
        }
     
        public void setEmail(String email) {
            this.email = email;
        }
     
        public Date getDateNaiss() {
            return dateNaiss;
        }
     
        public void setDateNaiss(Date dateNaiss) {
            this.dateNaiss = dateNaiss;
        }
     
        public Date getDateEmbauche() {
            return dateEmbauche;
        }
     
        public void setDateEmbauche(Date dateEmbauche) {
            this.dateEmbauche = dateEmbauche;
        }
     
        public String getFonction() {
            return fonction;
        }
     
        public void setFonction(String fonction) {
            this.fonction = fonction;
        }
     
        public Date getDateAffectation() {
            return dateAffectation;
        }
     
        public void setDateAffectation(Date dateAffectation) {
            this.dateAffectation = dateAffectation;
        }
     
        public String getPosteInterne() {
            return posteInterne;
        }
     
        public void setPosteInterne(String posteInterne) {
            this.posteInterne = posteInterne;
        }
     
        public String getIdagent() {
            return idagent;
        }
     
        public void setIdagent(String idagent) {
            this.idagent = idagent;
        }
     
        public Departement getIdDept() {
            return idDept;
        }
     
        public void setIdDept(Departement idDept) {
            this.idDept = idDept;
        }
     
        @XmlTransient
        public Collection<Intervention> getInterventionCollection() {
            return interventionCollection;
        }
     
        public void setInterventionCollection(Collection<Intervention> interventionCollection) {
            this.interventionCollection = interventionCollection;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (idagent != null ? idagent.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 Agentministere)) {
                return false;
            }
            Agentministere other = (Agentministere) object;
            if ((this.idagent == null && other.idagent != null) || (this.idagent != null && !this.idagent.equals(other.idagent))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "jpa.Agentministere[ idagent=" + idagent + " ]";
        }
     
    }
    Entité intervention
    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
    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
     
    package jpa;
     
    import java.io.Serializable;
    import java.util.Collection;
    import java.util.Date;
    import javax.persistence.Basic;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.GeneratedValue;
    import javax.persistence.GenerationType;
    import javax.persistence.Id;
    import javax.persistence.JoinColumn;
    import javax.persistence.ManyToOne;
    import javax.persistence.NamedQueries;
    import javax.persistence.NamedQuery;
    import javax.persistence.OneToMany;
    import javax.persistence.SequenceGenerator;
    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;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author Akrem
     */
    @Entity
    @Table(name = "INTERVENTION")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Intervention.findAll", query = "SELECT i FROM Intervention i"),
        @NamedQuery(name = "Intervention.findByIdIntervention", query = "SELECT i FROM Intervention i WHERE i.idIntervention = :idIntervention"),
        @NamedQuery(name = "Intervention.findByDateEmettre", query = "SELECT i FROM Intervention i WHERE i.dateEmettre = :dateEmettre"),
        @NamedQuery(name = "Intervention.findByDatePlanifiee", query = "SELECT i FROM Intervention i WHERE i.datePlanifiee = :datePlanifiee"),
        @NamedQuery(name = "Intervention.findByDateFinReparation", query = "SELECT i FROM Intervention i WHERE i.dateFinReparation = :dateFinReparation"),
        @NamedQuery(name = "Intervention.findByStatut", query = "SELECT i FROM Intervention i WHERE i.statut = :statut"),
        @NamedQuery(name = "Intervention.findByBesoin", query = "SELECT i FROM Intervention i WHERE i.besoin = :besoin")})
    public class Intervention implements Serializable {
        private static final long serialVersionUID = 1L;
        @Id
         @GeneratedValue(strategy= GenerationType.IDENTITY,generator="seq_intervention")
        @SequenceGenerator(name="seq_intervention",sequenceName="seq_intervention",allocationSize=1)
        @Basic(optional = false) 
        @NotNull
        @Size(min = 1, max = 30)
        @Column(name = "ID_INTERVENTION")
        private String idIntervention;
        @Column(name = "DATE_EMETTRE")
        @Temporal(TemporalType.TIMESTAMP)
        private Date dateEmettre;
        @Column(name = "DATE_PLANIFIEE")
        @Temporal(TemporalType.TIMESTAMP)
        private Date datePlanifiee;
        @Column(name = "DATE_FIN_REPARATION")
        @Temporal(TemporalType.TIMESTAMP)
        private Date dateFinReparation;
        @Size(max = 30)
        @Column(name = "STATUT")
        private String statut;
        @Size(max = 256)
        @Column(name = "BESOIN")
        private String besoin;
        @OneToMany(mappedBy = "idIntervention")
        private Collection<Facture> factureCollection;
        @JoinColumn(name = "IDTEC", referencedColumnName = "IDTEC")
        @ManyToOne
        private Technicien idtec;
        @JoinColumn(name = "IDSCANNER", referencedColumnName = "IDSCANNER")
        @ManyToOne
        private Scanner idscanner;
        @JoinColumn(name = "IDORD", referencedColumnName = "IDORD")
        @ManyToOne
        private Ordinateur idord;
        @JoinColumn(name = "IDIMP", referencedColumnName = "IDIMP")
        @ManyToOne
        private Imprimente idimp;
        @JoinColumn(name = "ID_FACT", referencedColumnName = "ID_FACT")
        @ManyToOne
        private Facture idFact;
        @JoinColumn(name = "ID_CATEGORIE", referencedColumnName = "ID_CATEGORIE")
        @ManyToOne
        private Categorie idCategorie;
        @JoinColumn(name = "IDAGENT", referencedColumnName = "IDAGENT")
        @ManyToOne
        private Agentministere idagent;
     
        public Intervention() {
        }
     
        public Intervention(String idIntervention) {
            this.idIntervention = idIntervention;
        }
     
        public String getIdIntervention() {
            return idIntervention;
        }
     
        public void setIdIntervention(String idIntervention) {
            this.idIntervention = idIntervention;
        }
     
        public Date getDateEmettre() {
            return dateEmettre;
        }
     
        public void setDateEmettre(Date dateEmettre) {
            this.dateEmettre = dateEmettre;
        }
     
        public Date getDatePlanifiee() {
            return datePlanifiee;
        }
     
        public void setDatePlanifiee(Date datePlanifiee) {
            this.datePlanifiee = datePlanifiee;
        }
     
        public Date getDateFinReparation() {
            return dateFinReparation;
        }
     
        public void setDateFinReparation(Date dateFinReparation) {
            this.dateFinReparation = dateFinReparation;
        }
     
        public String getStatut() {
            return statut;
        }
     
        public void setStatut(String statut) {
            this.statut = statut;
        }
     
        public String getBesoin() {
            return besoin;
        }
     
        public void setBesoin(String besoin) {
            this.besoin = besoin;
        }
     
        @XmlTransient
        public Collection<Facture> getFactureCollection() {
            return factureCollection;
        }
     
        public void setFactureCollection(Collection<Facture> factureCollection) {
            this.factureCollection = factureCollection;
        }
     
        public Technicien getIdtec() {
            return idtec;
        }
     
        public void setIdtec(Technicien idtec) {
            this.idtec = idtec;
        }
     
        public Scanner getIdscanner() {
            return idscanner;
        }
     
        public void setIdscanner(Scanner idscanner) {
            this.idscanner = idscanner;
        }
     
        public Ordinateur getIdord() {
            return idord;
        }
     
        public void setIdord(Ordinateur idord) {
            this.idord = idord;
        }
     
        public Imprimente getIdimp() {
            return idimp;
        }
     
        public void setIdimp(Imprimente idimp) {
            this.idimp = idimp;
        }
     
        public Facture getIdFact() {
            return idFact;
        }
     
        public void setIdFact(Facture idFact) {
            this.idFact = idFact;
        }
     
        public Categorie getIdCategorie() {
            return idCategorie;
        }
     
        public void setIdCategorie(Categorie idCategorie) {
            this.idCategorie = idCategorie;
        }
     
        public Agentministere getIdagent() {
            return idagent;
        }
     
        public void setIdagent(Agentministere idagent) {
            this.idagent = idagent;
        }
     
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (idIntervention != null ? idIntervention.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 Intervention)) {
                return false;
            }
            Intervention other = (Intervention) object;
            if ((this.idIntervention == null && other.idIntervention != null) || (this.idIntervention != null && !this.idIntervention.equals(other.idIntervention))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "jpa.Intervention[ idIntervention=" + idIntervention + " ]";
        }
     
    }

  4. #4
    Membre Expert
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Juin 2007
    Messages
    2 938
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Ingénieur développement logiciels

    Informations forums :
    Inscription : Juin 2007
    Messages : 2 938
    Par défaut
    Bonsoir,
    Essaie ça :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    Query query =
                 getEntityManager().createQuery("SELECT intervention FROM Intervention as intervention WHERE intervention.idagent.nomAgent = :nom and intervention.idagent.prenomAgent= :prenom" );

Discussions similaires

  1. Problème d'installation oracle 8.1.7 sous NT
    Par Anonymous dans le forum Installation
    Réponses: 7
    Dernier message: 02/08/2002, 14h18
  2. Problème d'impression
    Par IngBen dans le forum C++Builder
    Réponses: 7
    Dernier message: 22/05/2002, 11h37
  3. Problème avec la mémoire virtuelle
    Par Anonymous dans le forum CORBA
    Réponses: 13
    Dernier message: 16/04/2002, 16h10
  4. Réponses: 6
    Dernier message: 25/03/2002, 21h11

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