Bonjour,
J'ai un problème de connexion entre Hibernate et Wamp server.
IIS étant installé sur ma machine sur le port 80, j'ai installé Apache sur le port 81 pour Wamp Server et dans mon fichier de config hibernate.cfg.xml j'ai mis ceci pour l'urlpour permettre à Hibernate de savoir où se trouve la base de données.
Code xml : Sélectionner tout - Visualiser dans une fenêtre à part <property name="hibernate.connection.url">jdbc:mysql://localhost:81:3306/DB_TRANSPORT_CARGAISON</property>
Malheureusement rien ne se passe, aucune exception non plus.
Voici mon fichier de config 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
20
21
22
23
24
25
26
27
28
29 <?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="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property> <property name="hibernate.connection.url">jdbc:mysql://localhost:81:3306/DB_TRANSPORT_CARGAISON</property> <property name="hibernate.connection.username">root</property> <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property> <!-- Enable Hibernate's automatic session context management --> <property name="current_session_context_class">thread</property> <!-- JDBC connection pool (use the built-in) --> <property name="connection.pool_size">1</property> <!-- Disable the second-level cache --> <property name="cache.provider_class">org.hibernate.cache.NoCacheProvider</property> <!-- Echo all executed SQL to stdout --> <property name="show_sql">false</property> <!-- Drop and re-create the database schema on startup --> <property name="hbm2dll.auto">create</property> <mapping resource="dao/Cargaison.hbm.xml"/> <mapping resource="dao/Marchandise.hbm.xml"/> </session-factory> </hibernate-configuration>
mon fichier hibernateUtil.java :
cargaison.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
23
24
25
26 package util; import org.hibernate.SessionFactory; import org.hibernate.cfg.Configuration; public class HibernateUtil { public static final SessionFactory sessionFactory; static { try { // Création de la SessionFactory à partir de hibernate.cfg.xml sessionFactory = new Configuration().configure().buildSessionFactory(); } catch (Throwable ex) { // Make sure you log the exception, as it might be swallowed System.err.println("Initial SessionFactory creation failed." + ex); throw new ExceptionInInitializerError(ex); } } public static final ThreadLocal session = new ThreadLocal(); public static SessionFactory getSessionFactory() { return sessionFactory; } }
Marchandise.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
22
23
24
25
26 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD 3.0//EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Sep 3, 2014 10:46:22 AM by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="dao.Cargaison" table="CARGAISON"> <id name="reference" column="REF_CARG"></id> <discriminator column="TYPE_CARG" type="string" length="2"></discriminator> <property name="distance" type="double"> <column name="DISTANCE" /> </property> <property name="dateLivraison" type="java.util.Date"> <column name="DATELIVRAISON" /> </property> <set name="listeMarchandises" inverse="true" lazy="true"> <key column="REF_CARG"></key> <one-to-many class="dao.Marchandise" /> </set> <subclass name="dao.CargaisonAerienne" discriminator-value="CA"> <property name="poidsMax"></property> </subclass> <subclass name="dao.CargaisonRoutiere" discriminator-value="CR"> <property name="temperature"></property> </subclass> </class> </hibernate-mapping>
et la réponse d'Eclipse :
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 <?xml version="1.0"?> <!DOCTYPE hibernate-mapping PUBLIC "-//Hibernate/Hibernate Mapping DTD //EN" "http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd"> <!-- Generated Sep 3, 2014 10:46:22 AM by Hibernate Tools 3.4.0.CR1 --> <hibernate-mapping> <class name="dao.Marchandise" table="MARCHANDISE"> <id name="numero" column="NUMERO" > <generator class='native'></generator> </id> <property name="poids"> </property> <property name="volume"> </property> <property name="nom"> </property> <many-to-one name="cargaison" column="REF_CARG"></many-to-one> </class> </hibernate-mapping>
A l'exécution de TestDao:log4j:WARN No appenders could be found for logger (org.hibernate.cfg.Environment).
log4j:WARN Please initialize the log4j system properly.
Quelqu'un saurait-il m'expliquer ce qui se passe et comment résoudre ce problème ?
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11 package dao; import util.HibernateUtil; public class TestDao { public static void main(String[] args) { HibernateUtil.getSessionFactory(); } }
Merci d'avance pour votre aide.
Partager