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 :

beaucoup de requete pour un update jpa


Sujet :

JPA Java

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

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Points : 72
    Points
    72
    Par défaut beaucoup de requete pour un update jpa
    bonjour,
    j'ai un souci avais jpa lorsque j’effectue un update via : entity = em.merge(entity);
    j'ai essayer de tracer les requetes jpa envoyer et je trouve le nombre anormale voici le résultat :

    http://textup.fr/161740Ni

    Pouvez-vous m'aider ?

    Merci d'avance.

  2. #2
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    On est censé voir quoi dans cette tartine de texte? Tu peux définir 'anormal'. Il est où le code?

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

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Points : 72
    Points
    72
    Par défaut
    Pour un simple create(personne) j'ai mit le nombre de requête que fais JPA.
    Je trouve ça énorme . Vous trouvez ça normale ?
    Comment diminuer le nombre de requêtes SQL pour améliorer les performances.

    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
     
    /*
     * To change this license header, choose License Headers in Project Properties.
     * To change this template file, choose Tools | Templates
     * and open the template in the editor.
     */
    package fr.ietevents.client.Entity;
     
    import java.io.Serializable;
    import java.util.List;
    import javax.persistence.Basic;
    import javax.persistence.CascadeType;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.FetchType;
    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.Table;
    import javax.validation.constraints.NotNull;
    import javax.validation.constraints.Size;
    import javax.xml.bind.annotation.XmlRootElement;
    import javax.xml.bind.annotation.XmlTransient;
     
    /**
     *
     * @author IETEVENTS
     */
    @Entity
    @Table(name = "Personne")
    @XmlRootElement
    @NamedQueries({
        @NamedQuery(name = "Personne.findAll", query = "SELECT p FROM Personne p"),
        @NamedQuery(name = "Personne.findByKeyPersonne", query = "SELECT p FROM Personne p WHERE p.keyPersonne = :keyPersonne"),
      //  @NamedQuery(name = "Personne.CountPersonneParPay", query = "SELECT COUNT(p) FROM Personne p JOIN p.sessionCollection sc WHERE sc.keySession = :keySession and p.entreprise.adresse.localite.pays.keyPays = :keyPays and P.dateCreation BETWEEN :StatDate and :endate and p.typeInscription = :typeInscription"),
      //  @NamedQuery(name = "Personne.CountPersonneLocalite", query = "SELECT COUNT(p) FROM Personne p JOIN p.sessionCollection sc WHERE sc.keySession = :keySession and p.entreprise.adresse.localite.ville = :keyVille and P.dateCreation BETWEEN :StatDate and :endate and p.typeInscription = :typeInscription"),
      //  @NamedQuery(name = "Personne.CountPersonneTotal",  query = "SELECT COUNT(p) FROM Personne p JOIN p.sessionCollection sc WHERE sc.keySession = :keySession and P.dateCreation BETWEEN :StatDate and :endate and p.typeInscription = :typeInscription"),
        @NamedQuery(name = "Personne.findByNom", query = "SELECT p FROM Personne p WHERE p.nomPersonne = :nomPersonne"),
        @NamedQuery(name = "Personne.findByPrenom", query = "SELECT p FROM Personne p WHERE p.prenom = :prenom"),
        @NamedQuery(name = "Personne.findByEmail", query = "SELECT p FROM Personne p WHERE p.email = :email"),
        @NamedQuery(name = "Personne.findByTelephone", query = "SELECT p FROM Personne p WHERE p.telephone = :telephone"),
        @NamedQuery(name = "Personne.findByPortable", query = "SELECT p FROM Personne p WHERE p.portable = :portable"),
        @NamedQuery(name = "Personne.findByFax", query = "SELECT p FROM Personne p WHERE p.fax = :fax"),
        @NamedQuery(name = "Personne.findByActif", query = "SELECT p FROM Personne p WHERE p.actif = :actif")})
    public class Personne implements Serializable {
     
        private static final long serialVersionUID = 1L;
        @Id
        @Basic(optional = false)
        @NotNull
        @Column(name = "KeyPersonne")
        private String keyPersonne;
        @Size(max = 90)
        @Column(name = "IdExterne")
        private String idExterne;
        @Size(max = 255)
        @Column(name = "NomPersonne")
        private String nomPersonne;
        @Size(max = 255)
        @Column(name = "Prenom")
        private String prenom;
        // @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 = 255)
        @Column(name = "Email")
        private String email;
        @Size(max = 255)
        @Column(name = "Telephone")
        private String telephone;
        @Size(max = 255)
        @Column(name = "Portable")
        private String portable;
        // @Pattern(regexp="^\\(?(\\d{3})\\)?[- ]?(\\d{3})[- ]?(\\d{4})$", message="Invalid phone/fax format, should be as xxx-xxx-xxxx")//if the field contains phone or fax number consider using this annotation to enforce field validation
        @Size(max = 255)
        @Column(name = "Fax")
        private String fax;
        @Size(max = 1)
        @Column(name = "actif")
        private String actif;
        @ManyToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "KeyEntreprise")
        private Entreprise entreprise;
        @ManyToOne(cascade = CascadeType.ALL)
        @JoinColumn(name = "KeyCivilite")
        private Civilite civilite;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<CorrespondanceImportation> CorrespondanceImportationCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<Hotesse> hotesseCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<Produit> produitCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<Droit> droitCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<AutreInformation> autreInformationCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<CrmLien> CrmLienCollection;
        @OneToMany(mappedBy = "personne",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<SessionPersonne> sessionPersonnes;
        @OneToMany(mappedBy = "utilisateur",cascade = CascadeType.ALL,fetch = FetchType.EAGER)
        private List<SessionPersonne> sessionUtilisateur;
     
     
        public Personne() {
        }
     
        public Personne(String keyClient) {
            this.keyPersonne = keyClient;
        }
     
        public String getKeyPersonne() {
            return keyPersonne;
        }
     
        public void setKeyPersonne(String keyPersonne) {
            this.keyPersonne = keyPersonne;
        }
     
        public String getIdExterne() {
            return idExterne;
        }
     
        public void setIdExterne(String idExterne) {
            this.idExterne = idExterne;
        }
        public String getNomPersonne() {
            return nomPersonne;
        }
     
        public void setNomPersonne(String nomPersonne) {
            this.nomPersonne = nomPersonne;
        }
     
        public String getPrenom() {
            return prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        public String getEmail() {
            return email;
        }
     
        public void setEmail(String email) {
            this.email = email;
        }
     
        public String getTelephone() {
            return telephone;
        }
     
        public void setTelephone(String telephone) {
            this.telephone = telephone;
        }
     
        public String getPortable() {
            return portable;
        }
     
        public void setPortable(String portable) {
            this.portable = portable;
        }
     
        public String getFax() {
            return fax;
        }
     
        public void setFax(String fax) {
            this.fax = fax;
        }
     
        public String getActif() {
            return actif;
        }
     
        public void setActif(String actif) {
            this.actif = actif;
        }
        @XmlTransient
        public List<SessionPersonne> getSessionPersonnes() {
            return sessionPersonnes;
        }
     
        public void setSessionPersonnes(List<SessionPersonne> sessionPersonnes) {
            this.sessionPersonnes = sessionPersonnes;
        }
     
        @XmlTransient
        public List<CrmLien> getCrmLienCollection() {
            return CrmLienCollection;
        }
     
        public void setCrmLienCollection(List<CrmLien> CrmLienCollection) {
            this.CrmLienCollection = CrmLienCollection;
        }
     
        public Entreprise getEntreprise() {
            return entreprise;
        }
     
        public void setEntreprise(Entreprise entreprise) {
            this.entreprise = entreprise;
        }
        @XmlTransient
        public List<CorrespondanceImportation> getCorrespondanceImportationCollection() {
            return CorrespondanceImportationCollection;
        }
     
        public void setCorrespondanceImportationCollection(List<CorrespondanceImportation> CorrespondanceImportationCollection) {
            this.CorrespondanceImportationCollection = CorrespondanceImportationCollection;
        }
     
        public Civilite getCivilite() {
            return civilite;
        }
     
        public void setCivilite(Civilite civilite) {
            this.civilite = civilite;
        }
        @XmlTransient
        public List<Hotesse> getHotesseCollection() {
            return hotesseCollection;
        }
     
        public void setHotesseCollection(List<Hotesse> hotesseCollection) {
            this.hotesseCollection = hotesseCollection;
        }
        @XmlTransient
        public List<Produit> getProduitCollection() {
            return produitCollection;
        }
     
        public void setProduitCollection(List<Produit> produitCollection) {
            this.produitCollection = produitCollection;
        }
        @XmlTransient
        public List<Droit> getDroitCollection() {
            return droitCollection;
        }
     
        public void setDroitCollection(List<Droit> droitCollection) {
            this.droitCollection = droitCollection;
        }
        @XmlTransient
        public List<AutreInformation> getAutreInformationCollection() {
            return autreInformationCollection;
        }
     
        public void setAutreInformationCollection(List<AutreInformation> autreInformationCollection) {
            this.autreInformationCollection = autreInformationCollection;
        }
        @XmlTransient
        public List<SessionPersonne> getSessionUtilisateur() {
            return sessionUtilisateur;
        }
     
        public void setSessionUtilisateur(List<SessionPersonne> sessionUtilisateur) {
            this.sessionUtilisateur = sessionUtilisateur;
        }
        @Override
        public int hashCode() {
            int hash = 0;
            hash += (keyPersonne != null ? keyPersonne.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 Personne)) {
                return false;
            }
            Personne other = (Personne) object;
            if ((this.keyPersonne == null && other.keyPersonne != null) || (this.keyPersonne != null && !this.keyPersonne.equals(other.keyPersonne))) {
                return false;
            }
            return true;
        }
     
        @Override
        public String toString() {
            return "fr.ietevents.client.Entity.Personne[ KeyPersonne=" + keyPersonne + " ]";
        }
     
    }


    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
     
           public T create(T entity) {
            EntityManager em = getEntityManager();
            EntityTransaction tx = em.getTransaction();
            System.out.println( "Début de la transaction");
            try {
               //  System.out.println( "Ajout du client dans la base en cours..." );
     
                tx.begin();
                em.flush();
               // em.persist(entity);
                entity = em.merge(entity);
     
                tx.commit();
               return entity;
     
            } catch (Exception e) {
                System.out.println("Erreur :" + e.getMessage());
                tx.rollback();
                return null;
     
            } finally {
               EntityManagerFactory emf = em.getEntityManagerFactory();
                emf.getCache().evictAll();
                em.close();
                // System.out.println( "Transaction validée");
                //emf.close();
     
            }
     
        }

  4. #4
    Expert éminent sénior
    Avatar de tchize_
    Homme Profil pro
    Ingénieur développement logiciels
    Inscrit en
    Avril 2007
    Messages
    25 481
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 44
    Localisation : Belgique

    Informations professionnelles :
    Activité : Ingénieur développement logiciels
    Secteur : High Tech - Éditeur de logiciels

    Informations forums :
    Inscription : Avril 2007
    Messages : 25 481
    Points : 48 806
    Points
    48 806
    Par défaut
    J'ai répondu dans ton autre sujet. Je rajoute que le CascadeAll est à éviter sur les relation one to many / many to one, car ça inclus le merge.

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

    Informations forums :
    Inscription : Octobre 2009
    Messages : 226
    Points : 72
    Points
    72
    Par défaut
    un grand merci pour tout tes conseil

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

Discussions similaires

  1. requete pour Update de 2 tables
    Par spilo dans le forum Requêtes
    Réponses: 1
    Dernier message: 27/09/2010, 15h19
  2. Requete pour un débutant
    Par sqlnoob dans le forum Langage SQL
    Réponses: 3
    Dernier message: 20/05/2005, 08h55
  3. [type de retour pour un update]
    Par viny dans le forum PostgreSQL
    Réponses: 7
    Dernier message: 21/03/2005, 21h08
  4. requete pour reccuperer une parti d'un resultat
    Par ViBy dans le forum Langage SQL
    Réponses: 6
    Dernier message: 03/09/2004, 09h33
  5. requete pour avoir CONTENU procedures stockees
    Par bmayer dans le forum MS SQL Server
    Réponses: 11
    Dernier message: 11/02/2004, 13h20

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