Bonjour,
Je suis débutant avec hibernate et j'ai une erreur que je n'arrive pas à résoudre :
J'utilise hibernate + struts + tomcat + eclipse + mysql :
L'erreur est la suivante :
Could not parse mapping document from resource
dataBase/Utilisateur.hbm.xml
Le fichier Utilisateur.hbm.xml :
Code xml : 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 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <hibernate-mapping> <class name="dataBase/Utilisateur" table="utilisateur"> <id name="email" type="String" unsaved-value="null" > <column name="email" sql-type="char(40)" not-null="true"/> <generator class="assigned"/> </id> <property name="nom" column="nom"/> <property name="prenom" column="prenom"/> <property name="email" column="email"/> </class> </hibernate-mapping>
La class correspondante :
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 public class Utilisateur { public String email=null; public String nom=null; public String prenom=null; public Utilisateur() { } public String getEmail() { return email; } public void setEmail(String email) { this.email = email; } public String getNom() { return nom; } public void setNom(String nom) { this.nom = nom; } public String getPrenom() { return prenom; } public void setPrenom(String prenom) { this.prenom = prenom; } }
La table sous mysql :
Code sql : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 CREATE TABLE `utilisateur` ( `email` varchar(30) NOT NULL, `nom` varchar(20) NOT NULL, `prenom` varchar(20) NOT NULL, PRIMARY KEY (`email`) ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
le fichier hibernate.cfg.xml :
Code xml : 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-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/maDataBase</property> <property name="connection.username">root</property> <property name="connection.password">mae</property> <property name="show_sql">false</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <mapping resource="dataBase/Utilisateur.hbm.xml"/> </session-factory> </hibernate-configuration>
merci pour votre aide.
Partager