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 :

Table dont la clé primaire est composée


Sujet :

Hibernate Java

  1. #1
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut Table dont la clé primaire est composée
    Bonjour à tous,

    Je reviens encore sur un problème que je rencontre avec Hibernate. Lors de la création de mon application et de la configuration d'Hibernate, celui-ci m'a fabriqué tous les objets et mapping des mes tables contenant une clé primaire classique, SAUF QUE, je dispose d'une table dont la clé primaire est composée de deux clés étrangères.

    J'ai trouvé quelques tuto, mais toujours pas de résultat, voici ce que j'ai fait :

    1.J'ai crée une classe JAVA tel que Hibernate l'a fait automatiquement mais pour ma table dont la clé primaire est composée :

    2. J'ai créé un fichier MaTAble.hbm.xml en écrivant à la main les propriétés du mapping :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="domaine.Technicien" table="competencev2" catalog="comptechv2">
          <composite-id name="id" class="CompetenceId">
              <key-property name="id_technicien"/>
              <key-property name="id_technique"/>
          </composite-id>
     
          <property name="note" type="string">
              <column name="note" not-null="true"/>
          </property>
     
          <many-to-one name="id_ft">
              <column name="id_technicien"/>
          </many-to-one>
     
          <many-to-one name="id_technique">
              <column name="id_technique"/>
          </many-to-one>
     
      </class>
     
    </hibernate-mapping>
    3.J'ai renseigné le fichier de configuration de Hibernate hibernate.cfg.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/comptechv2</property>
        <property name="hibernate.connection.username">root</property>
        <!--    Affiches les logs sql-->
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <property name="use_sql_comments">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!--    Mapping-->
        <property name="hibernate.hbm2ddl.auto">create</property>
        <!--    Fichier à mapper-->
        <!--    <mapping class="domaine/Competencev2"/>-->
        <mapping resource="domaine/Famille.hbm.xml"/>
        <mapping resource="domaine/Responsable.hbm.xml"/>
        <mapping resource="domaine/Localisation.hbm.xml"/>
        <mapping resource="domaine/Technique.hbm.xml"/>
        <mapping resource="domaine/Technicien.hbm.xml"/>
        <mapping resource="domaine/Domaine.hbm.xml"/>
        <mapping resource="domaine/Droit.hbm.xml"/>
        <mapping resource="domaine/Produit.hbm.xml"/>
        <mapping resource="domaine/Competencev2.hbm.xml"/>
      </session-factory>
    </hibernate-configuration>
    J'utilise Netbeans 7.1 comme IDE, est-il possible de configurer automatiquement le mapping de cette table ? (JPA Controler Classes From Entity Classes) ?

    Merci d'avance

  2. #2
    Membre émérite
    Homme Profil pro
    Inscrit en
    Mai 2011
    Messages
    328
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations forums :
    Inscription : Mai 2011
    Messages : 328
    Par défaut
    Salut,

    n'as tu pas oublié d'écrire la classe CompetenceId ?

    Si c'est fait, donne aussi le code des classes CompetenceId et Technicien.

    Et aussi donne nous la log quand tu compiles, surtout si ça plante

  3. #3
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Salut,

    Merci de ta réponse, je t'invite à consulter cette conversation que j'ai crée :
    http://www.developpez.net/forums/d12...ping-jpa-j2ee/

    Post #14, tout est expliqué.

    Au niveau des logs, hibernate m'indique qu'il n'arrive pas à atteindre la table competencev2.

    Qu'en dis tu ?

    Merci
    Fred

  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
    J'en reviens à ce que je t'avais dit sur les annotations...
    Tu as mis à la fois @EmbeddedId et @Embeddable alors que la doc précise que c'est l'un ou l'autre ...

  5. #5
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Salut,

    J'ai bien noté ta remarque chtig, mais par quoi le remplacer ?
    Modifier @EmbeddedId par @Id ?

    Merci

  6. #6
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Voici un exemple de log que j'obtiens en lançant un "From Technicien" :
    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
     
    org.hibernate.MappingException: class CompetenceId not found while looking for property: id_technicien
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
    	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
    	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2174)
    	at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1903)
    	at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1726)
    	at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:424)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:338)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:669)
    	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:519)
    	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    Caused by: java.lang.ClassNotFoundException: Will not load classes from default package (CompetenceId)
    	at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:199)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:186)
    	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
    	... 16 more
    Un point me dérange :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
     
    Caused by: java.lang.ClassNotFoundException: Will not load classes from default package (CompetenceId)
    Sachant que cette classe CompetenceId ne se trouve pas dans le "default package"

    Merci

  7. #7
    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
    Je te propose d'essayer de mettre le @Id sur l'attribut la classe Competencev2 et @Embeddable sur la classe CompetenceId.
    C'est ce que tu as fait qui a généré l'erreur que tu as donnée ?

  8. #8
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Bonjour à tous,

    J'ai effectué la modification, voila ce que j'obtiens dans le HQL Query de netbeans lorsque je lance un "From Technicien" :

    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
     
    org.hibernate.MappingException: class CompetenceId not found while looking for property: id_technicien
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:74)
    	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
    	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2174)
    	at org.hibernate.cfg.HbmBinder.bindComponent(HbmBinder.java:1903)
    	at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:1726)
    	at org.hibernate.cfg.HbmBinder.bindCompositeId(HbmBinder.java:424)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:338)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:669)
    	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:519)
    	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    Caused by: java.lang.ClassNotFoundException: Will not load classes from default package (CompetenceId)
    	at org.netbeans.ProxyClassLoader.loadClass(ProxyClassLoader.java:199)
    	at java.lang.ClassLoader.loadClass(ClassLoader.java:356)
    	at java.lang.Class.forName0(Native Method)
    	at java.lang.Class.forName(Class.java:186)
    	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:100)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:70)
    	... 16 more
    Niveau code :
    Technicien.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
     
    package domaine;
    // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
     
     
     
    /**
     * Technicien generated by hbm2java
     */
    @Entity
    public class Technicien implements java.io.Serializable {
     
        @Id
        @Column(name="id_ft")
        private String idFt;
     
        @OneToMany(mappedBy="technicien")
        private Set<Competencev2> techniques = new HashSet<Competencev2>();
     
        private Domaine domaine;
        private Localisation localisation;
        private Responsable responsable;
        private String nom;
        private String prenom;
        private String numGsm;
        private String mobilite;
        private String dateNaissance;
        private String depart;
     
     
        public Technicien() {
        }
     
        public Technicien(String idFt, Domaine domaine, Localisation localisation, Responsable responsable, String nom, String prenom, String numGsm, String mobilite, String dateNaissance, String depart) {
            this.idFt = idFt;
            this.domaine = domaine;
            this.localisation = localisation;
            this.responsable = responsable;
            this.nom = nom;
            this.prenom = prenom;
            this.numGsm = numGsm;
            this.mobilite = mobilite;
            this.dateNaissance = dateNaissance;
            this.depart = depart;
        }
     
        public String getIdFt() {
            return this.idFt;
        }
     
        public void setIdFt(String idFt) {
            this.idFt = idFt;
        }
     
        public Domaine getDomaine() {
            return this.domaine;
        }
     
        public void setDomaine(Domaine domaine) {
            this.domaine = domaine;
        }
     
        public Localisation getLocalisation() {
            return this.localisation;
        }
     
        public void setLocalisation(Localisation localisation) {
            this.localisation = localisation;
        }
     
        public Responsable getResponsable() {
            return this.responsable;
        }
     
        public void setResponsable(Responsable responsable) {
            this.responsable = responsable;
        }
     
        public String getNom() {
            return this.nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getPrenom() {
            return this.prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        public String getNumGsm() {
            return this.numGsm;
        }
     
        public void setNumGsm(String numGsm) {
            this.numGsm = numGsm;
        }
     
        public String getMobilite() {
            return this.mobilite;
        }
     
        public void setMobilite(String mobilite) {
            this.mobilite = mobilite;
        }
     
        public String getDateNaissance() {
            return this.dateNaissance;
        }
     
        public void setDateNaissance(String dateNaissance) {
            this.dateNaissance = dateNaissance;
        }
     
        public String getDepart() {
            return this.depart;
        }
     
        public void setDepart(String depart) {
            this.depart = depart;
        }
     
        /**
         * @return the techniques
         */
        public Set<Competencev2> getTechniques() {
            return techniques;
        }
     
        /**
         * @param techniques the techniques to set
         */
        public void setTechniques(Set<Competencev2> techniques) {
            this.techniques = techniques;
        }
     
    }
    Technicien.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
     
    <?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 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA -->
    <hibernate-mapping>
        <class name="domaine.Technicien" table="technicien" catalog="comptechv2">
            <id name="idFt" type="string">
                <column name="id_ft" length="8" />
                <generator class="assigned" />
            </id>
            <many-to-one name="domaine" class="domaine.Domaine" fetch="select">
                <column name="id_domaine" not-null="true" />
            </many-to-one>
            <many-to-one name="localisation" class="domaine.Localisation" fetch="select">
                <column name="id_loc" not-null="true" />
            </many-to-one>
            <many-to-one name="responsable" class="domaine.Responsable" fetch="select">
                <column name="id_reponsable" not-null="true" />
            </many-to-one>
            <property name="nom" type="string">
                <column name="nom" length="65535" not-null="true" />
            </property>
            <property name="prenom" type="string">
                <column name="prenom" length="65535" not-null="true" />
            </property>
            <property name="numGsm" type="string">
                <column name="num_gsm" length="50" not-null="true" />
            </property>
            <property name="mobilite" type="string">
                <column name="mobilite" length="65535" not-null="true" />
            </property>
            <property name="dateNaissance" type="string">
                <column name="date_naissance" length="50" not-null="true" />
            </property>
            <property name="depart" type="string">
                <column name="depart" length="50" not-null="true" />
            </property>
     
        </class>
    </hibernate-mapping>
    Technique.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
     
    package domaine;
    // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
     
    /**
     * Technique generated by hbm2java
     */
    @Entity
    public class Technique  implements java.io.Serializable {
     
        @Id
        @Column(name="id_technique")
         private Integer idTechnique;
     
        @OneToMany(mappedBy="technique")
        private Set<Competencev2> techniciens = new HashSet<Competencev2>();
     
         private Produit produit;
         private Domaine domaine;
         private String categorieTechnique;
         private String nomTechnique;
     
     
        public Technique() {
        }
     
        public Technique(Produit produit, Domaine domaine, String categorieTechnique, String nomTechnique) {
           this.produit = produit;
           this.domaine = domaine;
           this.categorieTechnique = categorieTechnique;
           this.nomTechnique = nomTechnique;
        }
     
     
        public Integer getIdTechnique() {
            return this.idTechnique;
        }
     
        public void setIdTechnique(Integer idTechnique) {
            this.idTechnique = idTechnique;
        }
     
        public Produit getProduit() {
            return this.produit;
        }
     
        public void setProduit(Produit produit) {
            this.produit = produit;
        }
        public Domaine getDomaine() {
            return this.domaine;
        }
     
        public void setDomaine(Domaine domaine) {
            this.domaine = domaine;
        }
        public String getCategorieTechnique() {
            return this.categorieTechnique;
        }
     
        public void setCategorieTechnique(String categorieTechnique) {
            this.categorieTechnique = categorieTechnique;
        }
        public String getNomTechnique() {
            return this.nomTechnique;
        }
     
        public void setNomTechnique(String nomTechnique) {
            this.nomTechnique = nomTechnique;
        }
     
        /**
         * @return the techniciens
         */
        public Set<Competencev2> getTechniciens() {
            return techniciens;
        }
     
        /**
         * @param techniciens the techniciens to set
         */
        public void setTechniciens(Set<Competencev2> techniciens) {
            this.techniciens = techniciens;
        }
    }
    Technique.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
     
    <?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 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA -->
    <hibernate-mapping>
        <class name="domaine.Technique" table="technique" catalog="comptechv2">
            <id name="idTechnique" type="java.lang.Integer">
                <column name="id_technique" />
                <generator class="identity" />
            </id>
            <many-to-one name="produit" class="domaine.Produit" fetch="select">
                <column name="code_produit" not-null="true" />
            </many-to-one>
            <many-to-one name="domaine" class="domaine.Domaine" fetch="select">
                <column name="id_domaine" not-null="true" />
            </many-to-one>
            <property name="categorieTechnique" type="string">
                <column name="categorie_technique" length="65535" not-null="true" />
            </property>
            <property name="nomTechnique" type="string">
                <column name="nom_technique" length="65535" not-null="true" />
            </property>
     
        </class>
    </hibernate-mapping>
    Competencev2.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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package domaine;
     
    import java.io.Serializable;
    import java.util.List;
    import javax.faces.model.SelectItem;
    import javax.persistence.*;
     
    /**
     *
     * @author NHDF1037
     */
    //Annotation pour déclarer la table de la bd
    @Entity
    public class Competencev2 implements Serializable {
        @Id
        private CompetenceId id;
     
        @Column(name="note")
        private String note;
     
        @ManyToOne
        @JoinColumn(name="id_technicien", insertable=false, updatable=false)
        private Technicien technicien;
     
        @ManyToOne
        @JoinColumn(name="id_technique", insertable=false, updatable=false)
        private Technique technique;
     
        private List<SelectItem> selectedCompetence;
     
        public Competencev2(){
     
        }
     
        public Competencev2(Technicien technicien, Technique technique,String note){
            this.technicien = technicien;
            this.technique = technique;
     
            technicien.getTechniques().add(this);
            technique.getTechniciens().add(this);
     
            this.id = new CompetenceId(technicien.getIdFt(), technique.getIdTechnique());
            this.note = note;
        }
     
        /**
         * @return the technicien
         */
        public Technicien getTechnicien() {
            return technicien;
        }
     
        /**
         * @return the technique
         */
        public Technique getTechnique() {
            return technique;
        }
     
        /**
         * @return the selectedCompetence
         */
        public List<SelectItem> getSelectedCompetence() {
            return selectedCompetence;
        }
     
        /**
         * @param selectedCompetence the selectedCompetence to set
         */
        public void setSelectedCompetence(List<SelectItem> selectedCompetence) {
            this.selectedCompetence = selectedCompetence;
        }
     
    }
    CompetenceId.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
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    package domaine;
     
    import java.io.Serializable;
    import javax.persistence.Column;
    import javax.persistence.Embeddable;
     
    /**
     *
     * @author NHDF1037
     */
    @Embeddable
    public class CompetenceId implements Serializable{
        @Column(name="id_technicien")
        private String idTechnicien;
     
        @Column(name="id_technique")
        private int idTechnique;
     
     
        public CompetenceId(){
     
        }
     
        public CompetenceId(String idTechnicien, int idTechnique){
            this.idTechnicien = idTechnicien;
            this.idTechnique = idTechnique;
        }
     
        @Override
        public boolean equals(Object obj) {
            if (obj == null) {
                return false;
            }
            if (getClass() != obj.getClass()) {
                return false;
            }
            final CompetenceId other = (CompetenceId) obj;
            if ((this.idTechnicien == null) ? (other.idTechnicien != null) : !this.idTechnicien.equals(other.idTechnicien)) {
                return false;
            }
            if (this.idTechnique != other.idTechnique) {
                return false;
            }
            return true;
        }
     
        @Override
        public int hashCode() {
            int hash = 7;
            hash = 59 * hash + this.idTechnique;
            return hash;
        }
     
    }
    Competencev2.hmb.xml (Que j'ai créé moi même) :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <hibernate-mapping>
      <class name="domaine.Technicien" table="competencev2" catalog="comptechv2">
          <composite-id name="id" class="CompetenceId">
              <key-property name="id_technicien"/>
              <key-property name="id_technique"/>
          </composite-id>
     
          <property name="note" type="string">
              <column name="note" not-null="true"/>
          </property>
     
          <many-to-one name="id_ft">
              <column name="id_technicien"/>
          </many-to-one>
     
          <many-to-one name="id_technique">
              <column name="id_technique"/>
          </many-to-one>
     
      </class>
     
    </hibernate-mapping>
    Tous les éléments sont là, je n'arrive pas à voir l'erreur !

    Merci

  9. #9
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Ce problème n'a donc pas de solution ..... ?

  10. #10
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Bonjour,
    dans Competencev2.hmb.xml

    tu n'as pas fais une tentative de :
    <composite-id name="id" class="domaine.CompetenceId">
    puisque l'erreur indique que CompetenceId est cherché dans le default package...

  11. #11
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Bonjour kox2ee,
    Merci de ta réponse, j'ai fait la modification, les erreurs ont changé :

    Lorsque je lance un "From Technicien" :
    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
     
    org.hibernate.PropertyNotFoundException: field [id_ft] not found on domaine.Technicien
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:122)
    	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:114)
    	at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:137)
    	at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:83)
    	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:71)
    	at org.hibernate.mapping.ToOne.setTypeUsingReflection(ToOne.java:58)
    	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2174)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2151)
    	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2041)
    	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:359)
    	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:273)
    	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:144)
    	at org.hibernate.cfg.Configuration.add(Configuration.java:669)
    	at org.hibernate.cfg.AnnotationConfiguration.processArtifactsOfType(AnnotationConfiguration.java:519)
    	at org.hibernate.cfg.AnnotationConfiguration.secondPassCompile(AnnotationConfiguration.java:286)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1286)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    J'ai du changer mes noms de variables pour qu'il les reconnaissent, mais je ne comprends pas pourquoi il ne trouve pas "id_ft" alors qu'elle est bien présente ;
    domaine.Technicien.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
     
    package domaine;
    // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
     
     
     
    /**
     * Technicien generated by hbm2java
     */
    @Entity
    public class Technicien implements java.io.Serializable {
     
        @Id
        @Column(name="id_ft")
        private String id_ft;
     
        @OneToMany(mappedBy="technicien")
        private Set<Competencev2> techniques = new HashSet<Competencev2>();
     
        private Domaine domaine;
        private Localisation localisation;
        private Responsable responsable;
        private String nom;
        private String prenom;
        private String numGsm;
        private String mobilite;
        private String dateNaissance;
        private String depart;
     
     
        public Technicien() {
        }
     
        public Technicien(String idFt, Domaine domaine, Localisation localisation, Responsable responsable, String nom, String prenom, String numGsm, String mobilite, String dateNaissance, String depart) {
            this.id_ft = idFt;
            this.domaine = domaine;
            this.localisation = localisation;
            this.responsable = responsable;
            this.nom = nom;
            this.prenom = prenom;
            this.numGsm = numGsm;
            this.mobilite = mobilite;
            this.dateNaissance = dateNaissance;
            this.depart = depart;
        }
     
        public String getId_ft() {
            return this.id_ft;
        }
     
        public void setId_ft(String id_ft) {
            this.id_ft = id_ft;
        }
     
        public Domaine getDomaine() {
            return this.domaine;
        }
     
        public void setDomaine(Domaine domaine) {
            this.domaine = domaine;
        }
     
        public Localisation getLocalisation() {
            return this.localisation;
        }
     
        public void setLocalisation(Localisation localisation) {
            this.localisation = localisation;
        }
     
        public Responsable getResponsable() {
            return this.responsable;
        }
     
        public void setResponsable(Responsable responsable) {
            this.responsable = responsable;
        }
     
        public String getNom() {
            return this.nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getPrenom() {
            return this.prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        public String getNumGsm() {
            return this.numGsm;
        }
     
        public void setNumGsm(String numGsm) {
            this.numGsm = numGsm;
        }
     
        public String getMobilite() {
            return this.mobilite;
        }
     
        public void setMobilite(String mobilite) {
            this.mobilite = mobilite;
        }
     
        public String getDateNaissance() {
            return this.dateNaissance;
        }
     
        public void setDateNaissance(String dateNaissance) {
            this.dateNaissance = dateNaissance;
        }
     
        public String getDepart() {
            return this.depart;
        }
     
        public void setDepart(String depart) {
            this.depart = depart;
        }
     
        /**
         * @return the techniques
         */
        public Set<Competencev2> getTechniques() {
            return techniques;
        }
     
        /**
         * @param techniques the techniques to set
         */
        public void setTechniques(Set<Competencev2> techniques) {
            this.techniques = techniques;
        }
     
    }
    Avez-vous une idée, je pense que l'on se rapproche
    Bonne soirée

  12. #12
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Bonjour,
    oui, on se rapproche...

    Ce peut être du à une incohérence entre la classe, et la déclaration du mapping dans le fichier xml...

    Peux tu remettre le mapping xml du Technicien.

  13. #13
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Bonjour,

    Voici mon fichier "Technicien.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA -->
    <hibernate-mapping>
      <class catalog="comptechv2" name="domaine.Technicien" table="technicien">
        <id name="id_ft" type="string">
          <column length="8" name="id_ft"/>
          <generator class="assigned"/>
        </id>
        <many-to-one class="domaine.Domaine" fetch="select" name="domaine">
          <column name="id_domaine" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Localisation" fetch="select" name="localisation">
          <column name="id_loc" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Responsable" fetch="select" name="responsable">
          <column name="id_reponsable" not-null="true"/>
        </many-to-one>
        <property name="nom" type="string">
          <column length="65535" name="nom" not-null="true"/>
        </property>
        <property name="prenom" type="string">
          <column length="65535" name="prenom" not-null="true"/>
        </property>
        <property name="numGsm" type="string">
          <column length="50" name="num_gsm" not-null="true"/>
        </property>
        <property name="mobilite" type="string">
          <column length="65535" name="mobilite" not-null="true"/>
        </property>
        <property name="dateNaissance" type="string">
          <column length="50" name="date_naissance" not-null="true"/>
        </property>
        <property name="depart" type="string">
          <column length="50" name="depart" not-null="true"/>
        </property>
      </class>
    </hibernate-mapping>
    Merci

  14. #14
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Bonjour,
    je crois qu'il faut essayer d'isoler les problèmes, sinon tu risques d'y passer un moment...

    • Met en commentaire tous les mappings de hibernate sauf celui du Technicien
    • Met en commentaire les relations (ManyToOne) dans le fichier de mapping du Technicien
    • Fait une requête From Technicien et dis nous ce que ça donne

  15. #15
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Bonjour,

    Voici les résultats de la manip :

    J'ai commenté les mapping sauf celui du Technicien dans le fichier hibernate.cfg.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
    <hibernate-configuration>
      <session-factory>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
        <property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost:3306/comptechv2</property>
        <property name="hibernate.connection.username">root</property>
        <!--    Affiches les logs sql-->
        <property name="hibernate.show_sql">true</property>
        <property name="hibernate.format_sql">true</property>
        <property name="use_sql_comments">true</property>
        <property name="hibernate.current_session_context_class">thread</property>
        <property name="hibernate.query.factory_class">org.hibernate.hql.classic.ClassicQueryTranslatorFactory</property>
        <!-- JDBC connection pool (use the built-in) -->
        <property name="connection.pool_size">1</property>
        <!--    Mapping-->
        <property name="hibernate.hbm2ddl.auto">create</property>
        <!--    Fichier à mapper-->
    <!--    <mapping class="domaine/Competencev2"/>
        <mapping resource="domaine/Famille.hbm.xml"/>
        <mapping resource="domaine/Responsable.hbm.xml"/>
        <mapping resource="domaine/Localisation.hbm.xml"/>
        <mapping resource="domaine/Technique.hbm.xml"/>-->
        <mapping resource="domaine/Technicien.hbm.xml"/>
    <!--    <mapping resource="domaine/Domaine.hbm.xml"/>
        <mapping resource="domaine/Droit.hbm.xml"/>
        <mapping resource="domaine/Produit.hbm.xml"/>
        <mapping resource="domaine/Competencev2.hbm.xml"/>-->
      </session-factory>
    </hibernate-configuration>
    Dans le fichier Technicien.hbm.xml, j'ai commenté les many-to-one :
    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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA -->
    <hibernate-mapping>
      <class catalog="comptechv2" name="domaine.Technicien" table="technicien">
        <id name="id_ft" type="string">
          <column length="8" name="id_ft"/>
          <generator class="assigned"/>
        </id>
    <!--    <many-to-one class="domaine.Domaine" fetch="select" name="domaine">
          <column name="id_domaine" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Localisation" fetch="select" name="localisation">
          <column name="id_loc" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Responsable" fetch="select" name="responsable">
          <column name="id_reponsable" not-null="true"/>
        </many-to-one>-->
        <property name="nom" type="string">
          <column length="65535" name="nom" not-null="true"/>
        </property>
        <property name="prenom" type="string">
          <column length="65535" name="prenom" not-null="true"/>
        </property>
        <property name="numGsm" type="string">
          <column length="50" name="num_gsm" not-null="true"/>
        </property>
        <property name="mobilite" type="string">
          <column length="65535" name="mobilite" not-null="true"/>
        </property>
        <property name="dateNaissance" type="string">
          <column length="50" name="date_naissance" not-null="true"/>
        </property>
        <property name="depart" type="string">
          <column length="50" name="depart" not-null="true"/>
        </property>
      </class>
    </hibernate-mapping>
    Et lorsque je lance une requête "from Technicien", voilà ce que j'obtiens :
    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
     
    org.hibernate.exception.SQLGrammarException: could not execute query
    	at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:67)
    	at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
    	at org.hibernate.loader.Loader.doList(Loader.java:2223)
    	at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2104)
    	at org.hibernate.loader.Loader.list(Loader.java:2099)
    	at org.hibernate.hql.classic.QueryTranslatorImpl.list(QueryTranslatorImpl.java:912)
    	at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
    	at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1121)
    	at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
    Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'from limit 100' at line 1
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    	at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:57)
    	at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    	at java.lang.reflect.Constructor.newInstance(Constructor.java:525)
    	at com.mysql.jdbc.Util.handleNewInstance(Util.java:409)
    	at com.mysql.jdbc.Util.getInstance(Util.java:384)
    	at com.mysql.jdbc.SQLError.createSQLException(SQLError.java:1054)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3566)
    	at com.mysql.jdbc.MysqlIO.checkErrorPacket(MysqlIO.java:3498)
    	at com.mysql.jdbc.MysqlIO.sendCommand(MysqlIO.java:1959)
    	at com.mysql.jdbc.MysqlIO.sqlQueryDirect(MysqlIO.java:2113)
    	at com.mysql.jdbc.ConnectionImpl.execSQL(ConnectionImpl.java:2568)
    	at com.mysql.jdbc.PreparedStatement.executeInternal(PreparedStatement.java:2113)
    	at com.mysql.jdbc.PreparedStatement.executeQuery(PreparedStatement.java:2275)
    	at org.hibernate.jdbc.AbstractBatcher.getResultSet(AbstractBatcher.java:186)
    	at org.hibernate.loader.Loader.getResultSet(Loader.java:1787)
    	at org.hibernate.loader.Loader.doQuery(Loader.java:674)
    	at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:236)
    	at org.hibernate.loader.Loader.doList(Loader.java:2220)
    	... 8 more
    Merci

  16. #16
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Hibernate ne semble pas trouver le nom de la table associée à Technicien...
    peux tu essayer un from domaine.Technicien

  17. #17
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Voilà le résultat en faisant un "from domaine.Technicien" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    org.hibernate.PropertyNotFoundException: Could not find a getter for id_ft in class domaine.Technicien
    	at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
    	at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
    	at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
    	at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
    	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
    	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    J'ai donc vérifier la présence de mes getter/setter, ils sont bien là :

    Technicien.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
     
    package domaine;
    // Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA
     
    import java.util.HashSet;
    import java.util.Set;
    import javax.persistence.Column;
    import javax.persistence.Entity;
    import javax.persistence.Id;
    import javax.persistence.OneToMany;
     
     
     
    /**
     * Technicien generated by hbm2java
     */
    @Entity
    public class Technicien implements java.io.Serializable {
     
        @Id
        @Column(name="id_ft")
        private String id_ft;
     
        @OneToMany(mappedBy="technicien")
        private Set<Competencev2> techniques = new HashSet<Competencev2>();
     
        private Domaine domaine;
        private Localisation localisation;
        private Responsable responsable;
        private String nom;
        private String prenom;
        private String numGsm;
        private String mobilite;
        private String dateNaissance;
        private String depart;
     
     
        public Technicien() {
        }
     
        public Technicien(String idFt, Domaine domaine, Localisation localisation, Responsable responsable, String nom, String prenom, String numGsm, String mobilite, String dateNaissance, String depart) {
            this.id_ft = idFt;
            this.domaine = domaine;
            this.localisation = localisation;
            this.responsable = responsable;
            this.nom = nom;
            this.prenom = prenom;
            this.numGsm = numGsm;
            this.mobilite = mobilite;
            this.dateNaissance = dateNaissance;
            this.depart = depart;
        }
     
        public String getId_ft() {
            return this.id_ft;
        }
     
        public void setId_ft(String id_ft) {
            this.id_ft = id_ft;
        }
     
        public Domaine getDomaine() {
            return this.domaine;
        }
     
        public void setDomaine(Domaine domaine) {
            this.domaine = domaine;
        }
     
        public Localisation getLocalisation() {
            return this.localisation;
        }
     
        public void setLocalisation(Localisation localisation) {
            this.localisation = localisation;
        }
     
        public Responsable getResponsable() {
            return this.responsable;
        }
     
        public void setResponsable(Responsable responsable) {
            this.responsable = responsable;
        }
     
        public String getNom() {
            return this.nom;
        }
     
        public void setNom(String nom) {
            this.nom = nom;
        }
     
        public String getPrenom() {
            return this.prenom;
        }
     
        public void setPrenom(String prenom) {
            this.prenom = prenom;
        }
     
        public String getNumGsm() {
            return this.numGsm;
        }
     
        public void setNumGsm(String numGsm) {
            this.numGsm = numGsm;
        }
     
        public String getMobilite() {
            return this.mobilite;
        }
     
        public void setMobilite(String mobilite) {
            this.mobilite = mobilite;
        }
     
        public String getDateNaissance() {
            return this.dateNaissance;
        }
     
        public void setDateNaissance(String dateNaissance) {
            this.dateNaissance = dateNaissance;
        }
     
        public String getDepart() {
            return this.depart;
        }
     
        public void setDepart(String depart) {
            this.depart = depart;
        }
     
        /**
         * @return the techniques
         */
        public Set<Competencev2> getTechniques() {
            return techniques;
        }
     
        /**
         * @param techniques the techniques to set
         */
        public void setTechniques(Set<Competencev2> techniques) {
            this.techniques = techniques;
        }
     
    }
    Pour supprimer des erreurs, j'ai renommé la variable de "idFt" à "id_ft" pour qu'elle corresponde exactement au champs de ma table, peut il y avoir une influence ?

    Merci

  18. #18
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Je n'ai aucun problème sur ta classe Technicien...
    Ca fonctionne pour moi, avec ton mapping, et ta classe.

    Ca veut dire évidemment que l'erreur vient d'ailleurs, et en recopiant ton code pour créer les autres classes, j'ai vu une incohérence dans le fichier de mapping competencev2 :

    <class name="domaine.Technicien" table="competencev2" catalog="comptechv2">
    c'est domaine.Competencev2 la classe pas domaine.Technicien !
    Mais c'est peut-être une erreur que tu as corrigée depuis...

  19. #19
    Membre chevronné
    Homme Profil pro
    Ed Nat
    Inscrit en
    Janvier 2013
    Messages
    325
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : Ed Nat
    Secteur : High Tech - Multimédia et Internet

    Informations forums :
    Inscription : Janvier 2013
    Messages : 325
    Par défaut
    Une fois corrigé :
    competencev2.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
    <hibernate-mapping>
      <class name="domaine.Competencev2" table="competencev2">
          <composite-id name="id" class="domaine.CompetenceId">
              <key-property name="idTechnicien" column="id_technicien"/>
              <key-property name="idTechnique" column="id_technique"/>
          </composite-id>
     
          <property name="note" type="string">
              <column name="note" not-null="true"/>
          </property>
     
          <many-to-one name="technicien" insert="false" update="false">
              <column name="id_technicien"/>
          </many-to-one>
     
          <many-to-one name="technique" insert="false" update="false">
              <column name="id_technique"/>
          </many-to-one>
     
      </class>
     
    </hibernate-mapping>
    Pour le reste, il manquait pas mal d'accesseurs, mais ça, Hibernate devrait te le signaler explicitement.

    Sinon, juste 2 remarques :
    • Tu galères beaucoup parce que tu n'as pas adopté de convention de nommage claire (pour les champs, les membres des classes...) => met tout en camelCase par exemple, et respecte ce principe partout
    • Les types des champs de la base de données sont mis en dépit du bon sens : longText par exemple sur des champs tels que nom ou prenom : c'est-à-dire 65535 caractères ! Il ne faut pas oublier qu'avec un ORM toute erreur peut avoir des conséquences importantes sur les performances

  20. #20
    Membre confirmé
    Homme Profil pro
    Chef de projet MOA
    Inscrit en
    Janvier 2012
    Messages
    116
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Chef de projet MOA
    Secteur : High Tech - Matériel informatique

    Informations forums :
    Inscription : Janvier 2012
    Messages : 116
    Par défaut
    Salut Kox2ee,
    Merci pour ta réponse j'ai fait la modification, par contre j'ai encore le même problème quand je lance ma requête "from Technicien" :

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
     
    org.hibernate.PropertyNotFoundException: Could not find a getter for id_ft in class domaine.Technicien
    	at org.hibernate.property.BasicPropertyAccessor.createGetter(BasicPropertyAccessor.java:282)
    	at org.hibernate.property.BasicPropertyAccessor.getGetter(BasicPropertyAccessor.java:275)
    	at org.hibernate.tuple.PropertyFactory.getGetter(PropertyFactory.java:168)
    	at org.hibernate.tuple.PropertyFactory.buildIdentifierProperty(PropertyFactory.java:44)
    	at org.hibernate.tuple.entity.EntityMetamodel.<init>(EntityMetamodel.java:123)
    	at org.hibernate.persister.entity.AbstractEntityPersister.<init>(AbstractEntityPersister.java:434)
    	at org.hibernate.persister.entity.SingleTableEntityPersister.<init>(SingleTableEntityPersister.java:109)
    	at org.hibernate.persister.PersisterFactory.createClassPersister(PersisterFactory.java:55)
    	at org.hibernate.impl.SessionFactoryImpl.<init>(SessionFactoryImpl.java:226)
    	at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1294)
    	at org.hibernate.cfg.AnnotationConfiguration.buildSessionFactory(AnnotationConfiguration.java:859)
    Sachant que cette requête est lancée avec l'ensemble des mapping commentés :
    fichier web.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Production</param-value>
        </context-param>
        <context-param>
            <param-name>javax.faces.CONFIG_FILES</param-name>
            <param-value>/WEB-INF/faces-config.xml,
                /WEB-INF/FacesConfiguration.xml
            </param-value>
        </context-param>
     
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.xhtml</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>index.xhtml</welcome-file>
        </welcome-file-list>
    </web-app>
    J'ai également commenté les many-to-one dans le Technicien.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
     
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
    <!-- Generated 5 nov. 2012 11:48:38 by Hibernate Tools 3.2.1.GA -->
    <hibernate-mapping>
      <class catalog="comptechv2" name="domaine.Technicien" table="technicien">
        <id name="id_ft" type="string">
          <column length="8" name="id_ft"/>
          <generator class="assigned"/>
        </id>
    <!--    <many-to-one class="domaine.Domaine" fetch="select" name="domaine">
          <column name="id_domaine" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Localisation" fetch="select" name="localisation">
          <column name="id_loc" not-null="true"/>
        </many-to-one>
        <many-to-one class="domaine.Responsable" fetch="select" name="responsable">
          <column name="id_reponsable" not-null="true"/>
        </many-to-one>-->
        <property name="nom" type="string">
          <column length="65535" name="nom" not-null="true"/>
        </property>
        <property name="prenom" type="string">
          <column length="65535" name="prenom" not-null="true"/>
        </property>
        <property name="numGsm" type="string">
          <column length="50" name="num_gsm" not-null="true"/>
        </property>
        <property name="mobilite" type="string">
          <column length="65535" name="mobilite" not-null="true"/>
        </property>
        <property name="dateNaissance" type="string">
          <column length="50" name="date_naissance" not-null="true"/>
        </property>
        <property name="depart" type="string">
          <column length="50" name="depart" not-null="true"/>
        </property>
      </class>
    </hibernate-mapping>
    J'ai du mal à comprendre !
    Il dit qu'il ne trouve pas de getter alors que celui-ci est bien présent !

    Encore merci !

Discussions similaires

  1. [SQL 2008]:Requete SELECT sur table dont le nom n'est pas figé
    Par jaskoula1979 dans le forum Développement
    Réponses: 3
    Dernier message: 19/10/2011, 18h50
  2. Réponses: 9
    Dernier message: 16/11/2010, 16h58
  3. Réponses: 1
    Dernier message: 12/05/2009, 11h05
  4. Réponses: 2
    Dernier message: 18/12/2008, 16h24
  5. [MySQL] Créer une table dont la 1ere colonne est la recopie de celle d'une autre table
    Par Richard Trigaux dans le forum PHP & Base de données
    Réponses: 2
    Dernier message: 21/11/2007, 12h56

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