Salut les coupains,
je suis en train de me former sur Hibernate (v3), est j'ai un erreur récurrente que je n'arrive pas a résoudre.
Voici mon code : hibernate.cfg.xml
Ma classe principale : test1.javaCode:
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 <!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.url">jdbc:mysql://127.0.0.1/TP_BDD_Projet</property> <property name="connection.username">root</property> <property name="connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.pool_size">10</property> <property name="dialect">org.hibernate.dialect.MySQLDialect</property> <property name="connection.password">pass</property> <property name="show_sql">true</property> <property name="hibernate.current_session_context_class">thread</property> <mapping resource="ComporteMatiere.hbm.xml" /> <mapping resource="Libelleclasse.hbm.xml" /> <mapping resource="Matieres.hbm.xml" /> <mapping resource="Vaccination.hbm.xml" /> <mapping resource="Allergie.hbm.xml" /> <mapping resource="SubitAllergie.hbm.xml" /> <mapping resource="EstVaccine.hbm.xml" /> <mapping resource="Classe.hbm.xml" /> <mapping resource="Ancieneleve.hbm.xml" /> <mapping resource="EtudieMatiere.hbm.xml" /> <mapping resource="Note.hbm.xml" /> <mapping resource="Convocation.hbm.xml" /> <mapping resource="Comporteresponsable.hbm.xml" /> <mapping resource="Responsable.hbm.xml" /> <mapping resource="Etablissementprecedent.hbm.xml" /> <mapping resource="Eleve.hbm.xml" /> <mapping resource="Adresse.hbm.xml" /> <mapping resource="Etablissement.hbm.xml" /> <mapping resource="Medecin.hbm.xml" /> </session-factory> </hibernate-configuration>
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
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 package application; import java.util.List; import hibernate.DAOFactory; import hibernate.hibernate.HibernateUtil; import hibernate.pojo.Eleve; import org.hibernate.Session; import org.hibernate.SessionFactory; import org.hibernate.Transaction; import org.hibernate.cfg.Configuration; import org.hibernate.service.ServiceRegistry; import org.hibernate.service.ServiceRegistryBuilder; public class test1 { //private static SessionFactory sessionFactory; //private static ServiceRegistry serviceRegistry; public static void main(String[] args) { //Session session = null; Transaction t; try { try { //sessionFactory = new Configuration().configure() .buildSessionFactory(); //session = sessionFactory.getCurrentSession(); t = HibernateUtil.getSessionFactory().getCurrentSession().beginTransaction(); } catch (Throwable ex) { System.err.println("Failed to create sessionFactory object." + ex); throw new ExceptionInInitializerError(ex); } List<Eleve> eleves = DAOFactory.DEFAULT.buildEleveDAO().findAll(); for(Eleve eleve : eleves) { System.out.println(eleve); } } catch (Exception e) { System.out.println(e.getMessage()); } finally { //session.close(); //--cloture de la session HibernateUtil.getSessionFactory().close(); } } }
Lorsque que je lance le code j'ai cette erreur :
Enfin voici le fichier ComporteMatiere.hbm.xml ou semble se produire l'erreurCode:
1
2
3
4
5
6
7
8
9
10
11
12
13 ... INFO: HHH000221: Reading mappings from resource: ComporteMatiere.hbm.xml avr. 07, 2013 4:07:00 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! avr. 07, 2013 4:07:00 PM org.hibernate.internal.util.xml.ErrorLogger error ERROR: HHH000196: Error parsing XML (13) : Le contenu du type d'élément "class" doit correspondre à "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)". avr. 07, 2013 4:07:00 PM org.hibernate.internal.util.xml.DTDEntityResolver resolveEntity WARN: HHH000223: Recognized obsolete hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide! avr. 07, 2013 4:07:00 PM org.hibernate.internal.util.xml.ErrorLogger error ERROR: HHH000196: Error parsing XML (2) : Le contenu du type d'élément "class" doit correspondre à "(meta*,subselect?,cache?,synchronize*,comment?,tuplizer*,(id|composite-id),discriminator?,natural-id?,(version|timestamp)?,(property|many-to-one|one-to-one|component|dynamic-component|properties|any|map|set|list|bag|idbag|array|primitive-array)*,((join*,subclass*)|joined-subclass*|union-subclass*),loader?,sql-insert?,sql-update?,sql-delete?,filter*,fetch-profile*,resultset*,(query|sql-query)*)". Failed to create sessionFactory object.java.lang.ExceptionInInitializerError Exception in thread "main" java.lang.NoClassDefFoundError: Could not initialize class hibernate.hibernate.HibernateUtil at application.test1.main(test1.java:49)
J'ai chercher sur plusieurs forum la solution, mais je n'ai pas trouvé.Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14 <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- This file has been generated by Salto-db Generator v1.0.16 / Hibernate pojos and xml mapping files. at Sun Apr 07 16:03:17 BST 2013 --> <hibernate-mapping> <class name="hibernate.pojo.ComporteMatiere" table="comporte_Matiere"> <many-to-one name="classe" column="idClasse"/> <many-to-one name="matieres" column="libelleMatiere"/> </class> </hibernate-mapping>
Merci d'avance