Bonjour,

J'ai un bug dans mon fichier de mapping "Personne.hbm.xml", quand j'enlève le bout de code "en commentaire" :

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
<set name="voitures" inverse="true" cascade="save-update">
                <key column="ID_PERSONNE"/>       
                <one-to-many class="Voiture"/>   
        </set>
Ca marche et mes objets sont mappés et sauvegardés dans ma BD, mais quand j'enlève le commentaire, l'exécution s'interrompe, et un bug m'apparait en me disant :
Association references unmapped class : Voiture.
J'ai un pb dans ce bout de code qui permet le mapping des collections d'objets.

J'ai tout vérifié : le fichier de configuration, les fichiers de mapping ainsi que les fichiers beans. Je crois que tout est valide.

Mon fichier "Personne.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
package domaine;
 
import java.util.*;
 
public class Personne {
    private String cin;
    private String nom;
    private String prenom;
    private Set<Voiture> voitures = new HashSet<Voiture>();
    public Personne()
    {
        super();
    }
    public Personne(String cin,String nom ,String prenom)
    {        
        this.setCin(cin);
        this.setNom(nom);
        this.setPrenom(prenom);
    }
    public void setNom(String nom) {
        this.nom = nom;
    }
    public String getNom() {
        return nom;
    }
    public void setPrenom(String prenom) {
        this.prenom = prenom;
    }
    public String getPrenom() {
        return prenom;
    }
    public void setCin(String cin) {
        this.cin = cin;
    }
    public String getCin() {
        return cin;
    } 
    public void setVoitures(Set<Voiture> voitures)
    {
        this.voitures=voitures;
    }
    public void addVoiture(Voiture voiture)
    {
        voiture.setPersonne(this);
        this.voitures.add(voiture);
    }
}
Mon fichier "Voiture.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
package domaine;
 
public class Voiture {
    private String marque;
    private String matricule;
    private Personne personne;
    public Voiture()
    {
        super();
    }
    public Voiture(String marque,String matricule,Personne personne)
    {    
        this.setMarque(marque);
        this.setMatricule(matricule);
        this.setPersonne(personne);
    }
    public void setMarque(String marque) {
        this.marque = marque;
    }
    public String getMarque() {
        return marque;
    }
    public void setMatricule(String matricule) {
        this.matricule = matricule;
    }
    public String getMatricule() {
        return matricule;
    }
    public void setPersonne(Personne personne) {
        this.personne = personne;
    }
    public Personne getPersonne() {
        return personne;
    }
}
Mon mapping file "Personne.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
 
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="domaine.Personne" table="PERSONNE" catalog="test">
 
        <id column="ID_PERSONNE" type="integer">
            <generator class="increment" />
        </id>
        <property name="cin" column="CIN" type="string" length="10" not-null="true"/>
        <property name="nom" column="NOM" type="string" length="10" not-null="true"/>
        <property name="prenom" column="PRENOM" type="string" length="10" not-null="true"/>
        <!-- Le bug existe dans ce bout de code commenté !! -->
        <!-- 
        <set name="voitures" inverse="true" cascade="save-update">
            <key column="ID_PERSONNE"/>        
            <one-to-many class="Voiture"/>    
        </set>
        -->                 
    </class>
</hibernate-mapping>
Mon fichier mapping file "Voiture.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
 
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
    <class name="domaine.Voiture" table="Voiture" catalog="test">
 
        <id column="ID_VOITURE" type="integer">
            <generator class="increment" />
        </id>
        <property name="marque" column="MARQUE" type="string" length="10" not-null="true"/>
        <property name="matricule" column="MATRICULE" type="string" length="10" not-null="true"/>
        <many-to-one name="personne" column="ID_PERSONNE"/>         
    </class>
</hibernate-mapping>
Voici les logs que j'obtiens après la compilation/exécution :
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
78 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
78 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
78 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
94 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
203 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
203 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
328 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : domaine/Personne.hbm.xml
437 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: domaine.Personne -> PERSONNE
453 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : domaine/Voiture.hbm.xml
484 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: domaine.Voiture -> Voiture
578 [main] INFO org.hibernate.cfg.Configuration - Configured SessionFactory: null
Echec création SessionFactoryorg.hibernate.MappingException: Association references unmapped class: Voiture
Exception in thread "main" java.lang.ExceptionInInitializerError
    at hibernateUtil.HibernateUtil.<clinit>(HibernateUtil.java:17)
    at domaine.Main.main(Main.java:20)
Caused by: org.hibernate.MappingException: Association references unmapped class: Voiture
    at org.hibernate.cfg.HbmBinder.bindCollectionSecondPass(HbmBinder.java:2399)
    at org.hibernate.cfg.HbmBinder$CollectionSecondPass.secondPass(HbmBinder.java:2678)
    at org.hibernate.cfg.CollectionSecondPass.doSecondPass(CollectionSecondPass.java:66)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1177)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1333)
    at hibernateUtil.HibernateUtil.<clinit>(HibernateUtil.java:13)
    ... 1 more
Voici mon fichier de configuration "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
33
34
35
36
37
38
 
<?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.connection.driver_class">com.mysql.jdbc.Driver</property>
        <property name="hibernate.connection.password">root</property>
        <property name="hibernate.connection.url">jdbc:mysql://localhost/test</property>
        <property name="hibernate.connection.username">root</property>
        <property name="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</property>
 
           <!-- Enable Hibernate's automatic session context management -->
        <property name="current_session_context_class">thread</property>
 
        <!-- Cache niveau 2 EHCache-->  
        <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
        <!-- Utiliser le schéma de base de données existant au démarrage (utile pour tester chargement())
        <property name="hbm2ddl.auto">update</property>
        -->
 
        <!-- Formater le SQL de sortie -->
        <property name="hibernate.format_sql">true</property>
 
        <!-- Supprimer et re-créée le schéma de base de données au démarrage (utile pour tester insertion())-->
        <property name="hbm2ddl.auto">create</property>
 
        <!-- Montrer toutes les réquêtes générées -->
        <property name="show_sql">true</property>
 
        <property name="hibernate.generate_statistics">true</property>
 
        <mapping resource="domaine/Personne.hbm.xml"/>        
        <mapping resource="domaine/Voiture.hbm.xml"/>
    </session-factory>
</hibernate-configuration>
Quelqu'un saurait-il me dire d'où vient le problème ?

Merci d'avance pour votre aide.