Bonjour je suis le tutoriel d'hibernate depuis maintenant 5 jours et impossible d'arriver à qqch de concluant.
Entre les librairies non fournies dans les sources core etc etc me voila arrivé à cette erreur et la je bloque

Mon fichier de conf hibernate : hibernate.cfg.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
27
28
29
30
31
32
33
34
35
36
<?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>
 
	<!-- Database connection settings -->
	<property name="connection.driver_class">com.mysql.jdbc.Driver</property>
	<property name="connection.url">jdbc:mysql://localhost/entreprise</property>
	<property name="connection.username">root</property>
	<property name="connection.password">admin</property>
 
	<!-- JDBC connection pool (use the built-in) -->
	<property name="connection.pool_size">1</property>
 
	<!-- SQL dialect -->
	<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
 
	<!-- Enable Hibernate's automatic session context management -->
	<property name="current_session_context_class">thread</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">true</property>
 
	<!-- Drop and re-create the database schema on startup -->
	<property name="hbm2ddl.auto">create</property>
 
	<mapping resource="events/Event.hbm.xml"/>
 
	</session-factory>
</hibernate-configuration>
Mon petit bean : Event.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
25
26
27
28
29
30
31
32
33
34
35
36
package events;
 
import java.util.Date;
 
public class Event {
 
	private Long id;
	private String title;
	private Date date;
 
	public Event() {}
 
	public Long getId() {
		return id;
	}
 
	private void setId(Long id) {
		this.id = id;
	}
 
	public Date getDate() {
		return date;
	}
 
	public void setDate(Date date) {
		this.date = date;
	}
 
	public String getTitle() {
		return title;
	}
 
	public void setTitle(String title) {
		this.title = title;
	}
}
Mon fichier de mapping qui va avec : Event.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"?>
<!DOCTYPE hibernate-mapping PUBLIC
	"-//Hibernate/Hibernate Mapping DTD 3.0//EN"
	"http://hibernate.sourceforge.net/hibernate-mapping-3.0.dtd">
 
<hibernate-mapping>
 
	<class name="Event" table="EVENTS">
 
		<id name="id" column="EVENT_ID">
			<generator class="increment"/>
		</id>
 
		<property name="date" type="timestamp" column="EVENT_DATE"/>
		<property name="title"/>
	</class>
 
</hibernate-mapping>
Ma class 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
25
package util;
 
import org.hibernate.*;
import org.hibernate.cfg.*;
 
public class HibernateUtil {
 
	public static final SessionFactory sessionFactory;
 
	static {
		try {
			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;
	}
}
et enfin ma class principale d'execution : Eventmanager.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
25
26
27
28
29
 
package events;
 
import org.hibernate.Session;
 
import util.HibernateUtil;
 
import java.util.Date;
 
public class EventManager {
 
	public static void main(String[] args) {
		EventManager mgr = new EventManager();
		if (args[0].equals("store")) {
			mgr.createAndStoreEvent("My Event", new Date());
		}
		HibernateUtil.getSessionFactory().close();
	}
 
	private void createAndStoreEvent(String title, Date theDate) {
		Session session = HibernateUtil.getSessionFactory().getCurrentSession();
		session.beginTransaction();
		Event theEvent = new Event();
		theEvent.setTitle(title);
		theEvent.setDate(theDate);
		session.save(theEvent);
		session.getTransaction().commit();
	}
}
Voila la log que j'obtient : ( niveau de l'erreur )

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
[java] Initial SessionFactory creation failed.org.hibernate.InvalidMappingException: Could not parse mapping document from resource events/Event.hbm.xml
     [java] Exception in thread "main" java.lang.ExceptionInInitializerError
     [java] 	at util.HibernateUtil.<clinit>(Unknown Source)
     [java] 	at events.EventManager.createAndStoreEvent(Unknown Source)
     [java] 	at events.EventManager.main(Unknown Source)
     [java] Caused by: org.hibernate.InvalidMappingException: Could not parse mapping document from resource events/Event.hbm.xml
     [java] 	at org.hibernate.cfg.Configuration.addResource(Configuration.java:616)
     [java] 	at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1635)
     [java] 	at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1603)
     [java] 	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1582)
     [java] 	at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1556)
     [java] 	at org.hibernate.cfg.Configuration.configure(Configuration.java:1476)
     [java] 	at org.hibernate.cfg.Configuration.configure(Configuration.java:1462)
     [java] 	... 3 more
     [java] Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
     [java] 	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:232)
     [java] 	at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:302)
     [java] 	at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:423)
     [java] 	at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:356)
     [java] 	at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:295)
     [java] 	at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:166)
     [java] 	at org.hibernate.cfg.Configuration.add(Configuration.java:716)
     [java] 	at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:551)
     [java] 	at org.hibernate.cfg.Configuration.addResource(Configuration.java:613)
     [java] 	... 9 more
     [java] Caused by: java.lang.ClassNotFoundException: Event
     [java] 	at java.net.URLClassLoader$1.run(Unknown Source)
     [java] 	at java.security.AccessController.doPrivileged(Native Method)
     [java] 	at java.net.URLClassLoader.findClass(Unknown Source)
     [java] 	at java.lang.ClassLoader.loadClass(Unknown Source)
     [java] 	at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
     [java] 	at java.lang.ClassLoader.loadClass(Unknown Source)
     [java] 	at java.lang.ClassLoader.loadClassInternal(Unknown Source)
     [java] 	at java.lang.Class.forName0(Native Method)
     [java] 	at java.lang.Class.forName(Unknown Source)
     [java] 	at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:192)
     [java] 	at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:228)
     [java] 	... 17 more
     [java] Java Result: 1
Est ce que qqun peut m'expliquer pourquoi il en veut pas de mon fichier de mapping ?

J'ai peut etre une piste mais franchement je comprend pas , en gros la ligne de code du fichier Eventmanager.java

HibernateUtil.getSessionFactory().close();
Session session = HibernateUtil.getSessionFactory().getCurrentSession();

me sort une erreur ( sous eclipse souligné de rouge ) : HibernateUtil ne peut etre resolu

et

Event theEvent = new Event(); n'est pas reconnu comme type valide.


Voila la ça me depasse sachant que mon arborescence c'est :

src -- events -- Event.java
Event.hbm.xml
Eventmanager.java ( class main d'execution )
-- util -- HibernateUtil.java
Hibernate.cfg.xml


Merci à vous d'avance