Bonjour,

J'ai un problème avec Hibernate que je ne comprends pas.
J'ai crée deux classes Personne et DetailPersonne dans mon projet et je voudrais faire le mapping ces classes dans les tables TPersonne et TDetailPersonne de ma base de données.
Quand j'exécute mon application à partir d'Eclipse voici l'erreur que j'obtiens :
Toutes mes excuses si ma préoccupation parait bête, en fait je suis totalement nouveau au framework hibernate. C'est mon premier test avec le mapping OneToOne.

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
 
16 [main] INFO org.hibernate.cfg.Environment - Hibernate 3.3.2.GA
16 [main] INFO org.hibernate.cfg.Environment - hibernate.properties not found
31 [main] INFO org.hibernate.cfg.Environment - Bytecode provider name : javassist
31 [main] INFO org.hibernate.cfg.Environment - using JDK 1.4 java.sql.Timestamp handling
116 [main] INFO org.hibernate.cfg.Configuration - configuring from resource: /hibernate.cfg.xml
116 [main] INFO org.hibernate.cfg.Configuration - Configuration resource: /hibernate.cfg.xml
209 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/Personne.hbm.xml
319 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.Personne -> TPersonne
350 [main] INFO org.hibernate.cfg.Configuration - Reading mappings from resource : bean/DetailPersonne.hbm.xml
381 [main] INFO org.hibernate.cfg.HbmBinder - Mapping class: bean.DetailPersonne -> TDetailPersonne
Echec creation session factory org.hibernate.InvalidMappingException: Could not parse mapping document from resource bean/DetailPersonne.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
	at util.HibernateUtil.<clinit>(HibernateUtil.java:15)
	at manager.PersonneManager.ajouterPersonne(PersonneManager.java:12)
	at test.Main.main(Main.java:16)
Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource bean/DetailPersonne.hbm.xml
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
	at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
	at util.HibernateUtil.<clinit>(HibernateUtil.java:12)
	... 2 more
Caused by: org.hibernate.PropertyNotFoundException: field [situationMatrimoniale] not found on bean.DetailPersonne
	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:145)
	at org.hibernate.property.DirectPropertyAccessor.getField(DirectPropertyAccessor.java:137)
	at org.hibernate.property.DirectPropertyAccessor.getGetter(DirectPropertyAccessor.java:160)
	at org.hibernate.util.ReflectHelper.getter(ReflectHelper.java:241)
	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:229)
	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
	at org.hibernate.cfg.HbmBinder.createProperty(HbmBinder.java:2193)
	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2170)
	at org.hibernate.cfg.HbmBinder.createClassProperties(HbmBinder.java:2060)
	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:381)
	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
	at org.hibernate.cfg.Configuration.add(Configuration.java:716)
	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
	at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
	... 9 more

Fichier hibernate.cfg.xml généré:

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
 
<?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="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="connection.url">jdbc:mysql://localhost:3306/bd_personne</property>
<property name="connection.username">root</property>
<property name="connection.password"></property>
 
<property name="connection.pool_size">1</property>
 
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
 
<property name="current_session_context_class">thread</property>
 
<property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property>
 
<property name="show_sql">true</property>
 
<property name="hbm2ddl.auto">update</property>
 
<mapping resource="bean/Personne.hbm.xml" />
<mapping resource="bean/DetailPersonne.hbm.xml" />
 
</session-factory>
</hibernate-configuration>

Fichier 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
 
<?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="bean.Personne" table="TPersonne">
<id name="idPersonne" column="idPersonne">
<generator class="increment" />
</id>
<property name="nomPersonne" column="nomPersonne" />
<property name="prenomPersonne" column="prenomPersonne" />
<property name="telephonePersonne" column="telephonePersonne" />
<property name="emailPersonne" column="emailPersonne" />
<one-to-one name="detailPersonne" class="bean.DetailPersonne" cascade="save-update" />
</class>
</hibernate-mapping>
Fichier DetailPersonne.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
 
<?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="bean.DetailPersonne" table="TDetailPersonne">
<id name="idPersonne" column="idPersonne">
<generator class="foreign">
<param name="property">personne</param>
</generator>
</id>
<property name="situationMatrimoniale" column="situationMatrimoniale" />
<property name="nomprenomConjoint" column="nomprenomConjoint" />
<property name="nombreEnfant" column="nombreEnfant" />
<one-to-one name="personne" class="bean.Personne" constrained="true" />
</class>
</hibernate-mapping>

Fichier HibernateUtil:

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
 
package util;
 
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
 
public class HibernateUtil {
 
	public static final SessionFactory sf;
 
	static{
		try{
			sf = new Configuration().configure().buildSessionFactory();
		}catch(Throwable e){
			System.err.println("Echec creation session factory "+e);
			throw new ExceptionInInitializerError(e);
		}
	}
 
	public static SessionFactory getSessionFactory(){
		return sf;
	}
 
}

Fichier PersonneManager.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
 
package manager;
 
import bean.Personne;
import bean.DetailPersonne;
import util.HibernateUtil;
import org.hibernate.Session;
 
public class PersonneManager {
 
	public void ajouterPersonne(String nomPersonne, String prenomPersonne,
			String telephonePersonne, String emailPersonne, DetailPersonne detailPersonne){
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Personne p = new Personne();
		p.setNomPersonne(prenomPersonne);
		p.setPrenomPersonne(prenomPersonne);
		p.setTelephonePersonne(telephonePersonne);
		p.setEmailPersonne(emailPersonne);
		p.setDetailPersonne(detailPersonne);
		session.save(p);
		session.getTransaction().commit();		
	}
}

Fichier Main.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
 
package test;
 
import util.HibernateUtil;
import bean.DetailPersonne;
import manager.PersonneManager;
 
public class Main {
 
	/**
         * @param args
         */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		DetailPersonne dpm = new DetailPersonne(2, "Marié", "FASSINOU M. Rose");
		PersonneManager pm = new PersonneManager();
		pm.ajouterPersonne("LAKATAN", "Adebayo G. Wilfried", "00229 97 85 87 11", "lakatan_wilfried@hotmail.fr",dpm);
		HibernateUtil.sf.close();
	}
 
}
Je ne trouve pas où est l'erreur...
Merci pour l'aide