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

Tomcat et TomEE Java Discussion :

[Hibernate][Tomcat] Select sur tables


Sujet :

Tomcat et TomEE Java

  1. #1
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut [Hibernate][Tomcat] Select sur tables
    Hello,

    Voici mon problème, je développe donc un webservice en utilisant les technologies suivantes :
    - Eclipse.
    - Tomcat.
    - Hibernate.
    - MySql.

    Je mappe donc les tables à l'aide d'hibernate.
    Et quand je fais un select sur certaines tables j'obtiens des valeurs NULL, alors que la table contient des valeurs.
    Mais pour d'autres pas de problème.

    Le problème pourrait-il venir du mapping des tables ? Si les tables ont mal été créées ?

    Merci

  2. #2
    Membre actif
    Inscrit en
    Mai 2005
    Messages
    217
    Détails du profil
    Informations personnelles :
    Âge : 42

    Informations forums :
    Inscription : Mai 2005
    Messages : 217
    Points : 220
    Points
    220
    Par défaut
    O_O ca va etre du de t'aider la :/

    Je precise le message initiale etait

    Citation Envoyé par parasol007
    Hello,

    Voici mon problème, je développe donc un webservice en utilisant les technologies suivantes :
    Mais il a ete edité
    ____

    Maintenant on va pouvoir t'aider

  3. #3
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    peux tu afficher ton mapping (qui pose probleme tant qu'a faire) et le code qui l'utilise ... et par la même occasion, bah affiche aussi tes classe (classe+attributs seulement) ... histoire que l'on regarde ce qui peut se passer

  4. #4
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut Ok
    Oki merci
    C'est parti :

    Voici le fichier Candidat.hbm.xml
    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
    
    <?xml version="1.0"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN"
    "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 11 mai 2006 16:11:59 by Hibernate Tools 3.1.0.beta5 -->
    <hibernate-mapping>
    <class name="com.artemis.models.Candidat" table="candidat" catalog="artemis">
    <comment></comment>
    <id name="canId" type="int">
    <column name="can_id" />
    <generator class="assigned" />
    </id>
    <many-to-one name="statutCandidat" class="com.artemis.models.StatutCandidat" fetch="select">
    <column name="sta_can_id">
    <comment></comment>
    </column>
    </many-to-one>
    <many-to-one name="origineCandidature" class="com.artemis.models.OrigineCandidature" fetch="select">
    <column name="ori_can_id">
    <comment></comment>
    </column>
    </many-to-one>
    <many-to-one name="categorie" class="com.artemis.models.Categorie" fetch="select">
    <column name="cat_id">
    <comment></comment>
    </column>
    </many-to-one>
    <many-to-one name="poste" class="com.artemis.models.Poste" fetch="select">
    <column name="pos_id">
    <comment></comment>
    </column>
    </many-to-one>
    <many-to-one name="region" class="com.artemis.models.Region" fetch="select">
    <column name="reg_id">
    <comment></comment>
    </column>
    </many-to-one>
    <property name="canNom" type="string">
    <column name="can_nom" length="45" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="canPrenom" type="string">
    <column name="can_prenom" length="45" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="canMail" type="string">
    <column name="can_mail" length="45" not-null="true">
    <comment></comment>
    

  5. #5
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut
    la suite
    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
    </column>
    </property>
    <property name="canLienCv" type="string">
    <column name="can_lien_cv" length="45">
    <comment></comment>
    </column>
    </property>
    <property name="canDateCreation" type="date">
    <column name="can_date_creation" length="10" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="canCommentaires" type="string">
    <column name="can_commentaires" length="65535">
    <comment></comment>
    </column>
    </property>
    <property name="canMailEnvoye" type="java.lang.Integer">
    <column name="can_mail_envoye">
    <comment></comment>
    </column>
    </property>
    <property name="canDateCvAnalyse" type="date">
    <column name="can_date_cv_analyse" length="10" not-null="true">
    <comment></comment>
    </column>
    </property>
    <property name="canStatutInfos" type="string">
    <column name="can_statut_infos" length="45">
    <comment></comment>
    </column>
    </property>
    <set name="candComps" inverse="true">
    <key>
    <column name="can_id" not-null="true">
    <comment></comment>
    </column>
    </key>
    <one-to-many class="com.artemis.models.CandComp" />
    </set>
    <set name="candDemaUtils" inverse="true">
    <key>
    <column name="can_id" not-null="true">
    <comment></comment>
    </column>
    </key>
    <one-to-many class="com.artemis.models.CandDemaUtil" />
    </set>
    <set name="candOffrUtils" inverse="true">
    <key>
    <column name="can_id" not-null="true">
    <comment></comment>
    </column>
    </key>
    <one-to-many class="com.artemis.models.CandOffrUtil" />
    </set>
    </class>
    </hibernate-mapping>
    
    [/code]

  6. #6
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut Comme promis ...lol
    La classe permettant de lister les candidats

    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
     
    import java.util.Enumeration;
    import java.util.Iterator;
    import java.util.List;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    /*
     * 
     *
     */
    public  class ListeCandidats extends HttpServlet
    {
     
     /**
      * 
      */
     private static final long serialVersionUID = 1L;
     
     public void doPost( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
        {
      PrintWriter out=res.getWriter();
     
       HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction();
       List result = HibernateUtil.getSessionFactory().getCurrentSession().createCriteria(Candidat.class).list();
            if (result.size() > 0) {
                 for (Iterator it = result.iterator(); it.hasNext();) {
                     Candidat can = (Candidat) it.next();
                     out.print(can.getCanNom());
                     }
          }
     
     
     
        }
        public void doGet( HttpServletRequest req, HttpServletResponse res ) throws ServletException, IOException
        {
              doPost(req,res);  
        }
    }

  7. #7
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut
    Mais par contre quand je lui demande d'afficher l'identifiant de la table, pas de problème. Mais pour les autres champs il me met NULL.

  8. #8
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    l'identifiant de la table ?!? tu veux dire de l'objet ?!? (enfin de l'enregistrement niveau BDD)

    Si il te trouve l'ID mais ne charge pas tout, c'est en effet genant ... sinon, pour ce qui est du mapping, je vois que tu n'as pas fait dans le detail ... ya pas mal de fioritures la dedans

    un tit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <property name="truc" column="truc_db" type="truc_type" />
    le rendrait sensiblement moins long je suis sûr

    EDIT : Ah oki, j'avais pas vu le
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <!-- Generated 11 mai 2006 16:11:59 by Hibernate Tools 3.1.0.beta5 -->
    ... je comprend mieux ! (vu la longueur, t'aurais pu faire ca à la main dediou )

  9. #9
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut
    tu me conseilles de faire tout le mapping à la main ?

  10. #10
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    pas forcément, si tu as 45678 classes avec 12589 champs ... autant générer ... maintenant si tu as 5 classes avec 10 champs chacune, je pense que le mapping manuel t'apportera trois choses :

    - un fichier plus lisible
    - un fichier plus adapté à tes besoins
    - une meilleure compréhension de ce que tu as fait et ainsi un debuggage plus aisé

    Maintenant, je n'utilise pas de générateur pour ma part, et n'ai jamais eu aucun souci ... le probleme est qu'ici, ton fichier de mapping n'est pas faux non plus d'après ce que je vois ... (enfin, mes paroles ne sont pas d'evangile hein )

    Il faut que je fouille plus en profondeur pour te dire cela, mais si ya d'autres amateurs Hibernate, qu'ils n'hésitent pas a mettre leur nez la dedans (n'est ce pas _beber85 (entre autres) ? ^^)

  11. #11
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    Tu peux ajouter la classe Candidat en même temps?

    Et quitte a être chiant, tu peux aussi activer l'affichage des requetes SQL réalisée par Hibernate et nous le montrer ici-même lors du lancement de ta servlet ?

    (dans le fichier de config d'hibernate, ca ressemble a ca :
    <property name="show_sql">true</property>)

  12. #12
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut
    voici mon Candidat.java :
    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
    package com.artemis.models;
    // Generated 12 mai 2006 11:15:11 by Hibernate Tools 3.1.0.beta5
    import java.util.Date;
    import java.util.HashSet;
    import java.util.Set;
    /**
     * Candidat generated by hbm2java
     */
    public class Candidat implements java.io.Serializable {
     // Fields    
     private int canId;
     private StatutCandidat statutCandidat;
     private OrigineCandidature origineCandidature;
     private Categorie categorie;
     private Poste poste;
     private Region region;
     private String canNom;
     private String canPrenom;
     private String canMail;
     private String canLienCv;
     private Date canDateCreation;
     private String canCommentaires;
     private Integer canMailEnvoye;
     private Date canDateCvAnalyse;
     private String canStatutInfos;
     private Set<CandComp> candComps = new HashSet<CandComp>(0);
     private Set<CandDemaUtil> candDemaUtils = new HashSet<CandDemaUtil>(0);
     private Set<CandOffrUtil> candOffrUtils = new HashSet<CandOffrUtil>(0);
     // Constructors
     /** default constructor */
     public Candidat() {
     }
     /** minimal constructor */
     public Candidat(int canId, String canNom, String canPrenom, String canMail,
       Date canDateCreation, Date canDateCvAnalyse) {
      this.canId = canId;
      this.canNom = canNom;
      this.canPrenom = canPrenom;
      this.canMail = canMail;
      this.canDateCreation = canDateCreation;
      this.canDateCvAnalyse = canDateCvAnalyse;
     }
     /** full constructor */
     public Candidat(int canId, StatutCandidat statutCandidat,
       OrigineCandidature origineCandidature, Categorie categorie,
       Poste poste, Region region, String canNom, String canPrenom,
       String canMail, String canLienCv, Date canDateCreation,
       String canCommentaires, Integer canMailEnvoye,
       Date canDateCvAnalyse, String canStatutInfos,
       Set<CandComp> candComps, Set<CandDemaUtil> candDemaUtils,
       Set<CandOffrUtil> candOffrUtils) {
      this.canId = canId;
      this.statutCandidat = statutCandidat;
      this.origineCandidature = origineCandidature;
      this.categorie = categorie;
      this.poste = poste;
      this.region = region;
      this.canNom = canNom;
      this.canPrenom = canPrenom;
      this.canMail = canMail;
      this.canLienCv = canLienCv;
      this.canDateCreation = canDateCreation;
      this.canCommentaires = canCommentaires;
      this.canMailEnvoye = canMailEnvoye;
      this.canDateCvAnalyse = canDateCvAnalyse;
      this.canStatutInfos = canStatutInfos;
      this.candComps = candComps;
      this.candDemaUtils = candDemaUtils;
      this.candOffrUtils = candOffrUtils;
     }
     // Property accessors
     public int getCanId() {
      return this.canId;
     }
     public void setCanId(int canId) {
      this.canId = canId;
     }
     public StatutCandidat getStatutCandidat() {
      return this.statutCandidat;
     }
     public void setStatutCandidat(StatutCandidat statutCandidat) {
      this.statutCandidat = statutCandidat;
     }
     public OrigineCandidature getOrigineCandidature() {
      return this.origineCandidature;
     }
     public void setOrigineCandidature(OrigineCandidature origineCandidature) {
      this.origineCandidature = origineCandidature;
     }
     public Categorie getCategorie() {
      return this.categorie;
     }
     public void setCategorie(Categorie categorie) {
      this.categorie = categorie;
     }
     public Poste getPoste() {
      return this.poste;
     }
     public void setPoste(Poste poste) {
      this.poste = poste;
     }
     public Region getRegion() {
      return this.region;
     }
     public void setRegion(Region region) {
      this.region = region;
     }
     public String getCanNom() {
      return this.canNom;
     }
     public void setCanNom(String canNom) {
      this.canNom = canNom;
     }
     public String getCanPrenom() {
      return this.canPrenom;
     }
     public void setCanPrenom(String canPrenom) {
      this.canPrenom = canPrenom;
     }
     public String getCanMail() {
      return this.canMail;
     }
     public void setCanMail(String canMail) {
      this.canMail = canMail;
     }
     public String getCanLienCv() {
      return this.canLienCv;
     }
     public void setCanLienCv(String canLienCv) {
      this.canLienCv = canLienCv;
     }
     public Date getCanDateCreation() {
      return this.canDateCreation;
     }
     public void setCanDateCreation(Date canDateCreation) {
      this.canDateCreation = canDateCreation;
     }
     public String getCanCommentaires() {
      return this.canCommentaires;
     }
     public void setCanCommentaires(String canCommentaires) {
      this.canCommentaires = canCommentaires;
     }
     public Integer getCanMailEnvoye() {
      return this.canMailEnvoye;
     }
     public void setCanMailEnvoye(Integer canMailEnvoye) {
      this.canMailEnvoye = canMailEnvoye;
     }
     public Date getCanDateCvAnalyse() {
      return this.canDateCvAnalyse;
     }
     public void setCanDateCvAnalyse(Date canDateCvAnalyse) {
      this.canDateCvAnalyse = canDateCvAnalyse;
     }
     public String getCanStatutInfos() {
      return this.canStatutInfos;
     }
     public void setCanStatutInfos(String canStatutInfos) {
      this.canStatutInfos = canStatutInfos;
     }
     public Set<CandComp> getCandComps() {
      return this.candComps;
     }
     public void setCandComps(Set<CandComp> candComps) {
      this.candComps = candComps;
     }
     public Set<CandDemaUtil> getCandDemaUtils() {
      return this.candDemaUtils;
     }
     public void setCandDemaUtils(Set<CandDemaUtil> candDemaUtils) {
      this.candDemaUtils = candDemaUtils;
     }
     public Set<CandOffrUtil> getCandOffrUtils() {
      return this.candOffrUtils;
     }
     public void setCandOffrUtils(Set<CandOffrUtil> candOffrUtils) {
      this.candOffrUtils = candOffrUtils;
     }
    }

  13. #13
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut thanks
    et voici ma requête qui est générée par Hibernate :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    
    select this_.com_id as com1_6_0_, this_.com_libelle as com2_6_0_, this_.com_date_ajout as com3_6_0_ from artemis.competence this_
    
    Je l ai testé avec SQLBrowser et il me retourne les bonnes valeurs.

    Merci pour ton aide.

  14. #14
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut
    je me serai bioen contenter de la classe et des attributs seulement ... manque plus que les requetes SQL et euh, après on aura tout

    Sinon pour la classe, elle doit etre generee automatiquement je présume ... d'après la base, donc je fais confiance a HibernateTools pour tout bien faire comme il faut ...

    Ce qui me chagrine c'est pourquoi ce probleme de null sur un attribut "simple" ...

    Bon on a tout ... ya rien qui te chagrine la?!? tu te dis pas qu'il ne demande que 3 champs alors que ta classe en necessite plus de 10 ?!? es tu sur de la requete en question ?!?

  15. #15
    Membre du Club
    Inscrit en
    Avril 2006
    Messages
    129
    Détails du profil
    Informations forums :
    Inscription : Avril 2006
    Messages : 129
    Points : 63
    Points
    63
    Par défaut
    Une bonne et une mauvaise nouvelle :
    - la bonne : Tout fonctionne.
    - la mauvaise : je ne sais pas pourquoi.

    Enfin j'ai effacé les données des tables, effacé tous les fichiers créés par hibernate tools et tout recréé.
    Et puis c'est passé.

    Et puis j'ai sorti la déclaration du candidat du for. (Au moment ou je récupère les valeurs de la List)

    Merci pour ton aide

  16. #16
    Membre éclairé Avatar de BizuR
    Profil pro
    Inscrit en
    Mai 2005
    Messages
    688
    Détails du profil
    Informations personnelles :
    Âge : 41
    Localisation : France

    Informations forums :
    Inscription : Mai 2005
    Messages : 688
    Points : 757
    Points
    757
    Par défaut

    Toujours est il que je suis sur que ca n'etait pas la bonne requete ...

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

Discussions similaires

  1. Problème select sur table/vue x$ksppsv
    Par LBO72 dans le forum Administration
    Réponses: 4
    Dernier message: 25/03/2009, 09h07
  2. INSERT / SELECT sur tables multiples
    Par AlexisB dans le forum Langage SQL
    Réponses: 2
    Dernier message: 03/11/2008, 15h17
  3. Select sur table de jointure qui pointe sur la meme Table.
    Par yakamax dans le forum Langage SQL
    Réponses: 2
    Dernier message: 25/06/2008, 11h44
  4. Réponses: 7
    Dernier message: 28/01/2008, 10h43
  5. Insert avec select sur table avec Trigger d'insertion
    Par bran_noz dans le forum Développement
    Réponses: 5
    Dernier message: 23/12/2005, 14h38

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