Hibernate 3.0 : problem parsing configuration/hibernate.cfg.xml
Bonjour,
Après quelques mois sur JDBC, je me suis mis à Hibernate 3.0 (enfin, mon patron me l'impose). Je tente depuis la semaine dernière de faire tourner une maquette, je me heurte sans arrêt à l'exception suivante :cry:
J'ai cherché sur le net et sur ce forum d'autres posts à ce sujet, je n'ai pas trouvé la solution. Et pourtant, comme dirait maître Yoda, "certain je suis que la solution sous mes yeux est". :oops:
Code:
1 2 3 4 5 6 7 8 9 10
|
Exception in thread "main" org.hibernate.HibernateException: problem parsing configuration/hibernate.cfg.xml
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1173)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1112)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1098)
at exe.Principale.main(Principale.java:19)
Caused by: org.dom4j.DocumentException: Error on line 2 of document : A pseudo attribute name is expected. Nested exception: A pseudo attribute name is expected.
at org.dom4j.io.SAXReader.read(SAXReader.java:482)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1168)
... 3 more |
L'exception indique que je dois mettre l'attribut "name" à la balise <session-factory>, mais pourquoi ?
Le fichier hibernate.hbm.xml est le suivant :
Code:
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-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
<session-factory>
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/championnat</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">justdoit</property>
<property name="show_sql">true</property>
<!-- Mapping -->
<mapping resource="/src/champ/Personne.hbm.xml"/>
</session-factory>
</hibernate-configuration> |
Je ne comprends pas pourquoi je dois mettre un attribut name à la balise <session-factory> alors que je suis en hibernate3... (le fichier MANIFEST.MF indique "Hibernate-Version: 3.0.5")
Autre précision : je n'utilise pas JNDI. Du moins, pour le moment ;)
Le fichier Personne.hbm.xml :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
|
<?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"~//Hibernate/Hibernate Mapping DTD 3.0//EN"
"/hibernate-mapping-3.0.dtd">
<hibernate-mapping>
<class name="Personne" table="PERSONNE">
<id name="OID" column="OID">
<generator class="increment"/>
</id>
<property name="nom"/>
<property name="prenom"/>
<property name="dateNaissance" type="timestamp" column="DATE_NAISSANCE"/>
<property name="licence"/>
<property name="arbitre" column="ESTARBITRE"/>
<property name="joueur" column="ESTJOUEUR"/>
<property name="president" column="ESTPRESIDENT"/>
</class>
</hibernate-mapping> |
Enfin, la classe Principale.java très simplifiée :
Code:
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
|
package exe;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class Principale {
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Configuration configuration;
Session session;
SessionFactory sessionFactory;
//try {
configuration = new Configuration();
sessionFactory = configuration.configure().buildSessionFactory();
session = sessionFactory.openSession();
/*} catch (Exception e) {
System.out.println(e.toString());
}*/
}
} |
Si quelqu'un pouvait m'éclairer sur le pourquoi de cette exception, je l'en remercie d'avance. Il est évident que je n'ai pas tout compris d'Hibernate...