[HIBERNATE] Conf et classe not found
Bonjour,
Voila je débute avec hibernate et j'ai le soucis suivant :
j'utilise une doc d'hibernate et j'en suis à mon premier essaie, j'ai fait les fichiers de conf et le mapping et lorsque je lance mon test java me dit qu'il ne trouve pas mon POJO, voici mon exemple :
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
| package events;
import java.util.Date;
public class Event {
private long id;
private String title;
private Date date;
/**
* @return Returns the date.
*/
public Date getDate() {
return date;
}
/**
* @param date The date to set.
*/
public void setDate(Date date) {
this.date = date;
}
/**
* @return Returns the id.
*/
public long getId() {
return id;
}
/**
* @param id The id to set.
*/
public void setId(long id) {
this.id = id;
}
/**
* @return Returns the title.
*/
public String getTitle() {
return title;
}
/**
* @param title The title to set.
*/
public void setTitle(String title) {
this.title = title;
}
} |
C'est mon object events que j'utilise et voici le mapping associé :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
<?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>
|
Voici aussi mon fichier de conf hibernate
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
|
<?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">org.hsqldb.jdbcDriver</property>
<property name="connection.url">jdbc:hsqldb:hsql://localhost</property>
<property name="connection.username">sa</property>
<property name="connection.password"></property>
<!-- JDBC connection pool (use the built-in) -->
<property name="connection.pool_size">1</property>
<!-- SQL dialect -->
<property name="dialect">org.hibernate.dialect.HSQLDialect</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 shema on startup -->
<property name="hbm2ddl.auto">create</property>
<mapping resource="events/Event.hbm.xml"/>
</session-factory>
</hibernate-configuration>
|
Et quand je lance mon programme pour qu'il ajout un objet event dans ma base, voila l'erreur :
Citation:
Initial SessionFactory creation failed.org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
Exception in thread "main" java.lang.ExceptionInInitializerError
at util.HibernateUtil.<clinit>(Unknown Source)
at events.EventManager.createAndStoreEvent(Unknown Source)
at events.EventManager.main(Unknown Source)
Caused by: org.hibernate.MappingException: Could not read mappings from resource: events/Event.hbm.xml
at org.hibernate.cfg.Configuration.addResource(Configuration.java:485)
at org.hibernate.cfg.Configuration.parseMappingElement(Configuration.java:1465)
at org.hibernate.cfg.Configuration.parseSessionFactory(Configuration.java:1433)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1414)
at org.hibernate.cfg.Configuration.doConfigure(Configuration.java:1390)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1310)
at org.hibernate.cfg.Configuration.configure(Configuration.java:1296)
... 3 more
Caused by: org.hibernate.MappingException: class Event not found while looking for property: id
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:80)
at org.hibernate.mapping.SimpleValue.setTypeUsingReflection(SimpleValue.java:276)
at org.hibernate.cfg.HbmBinder.bindSimpleId(HbmBinder.java:410)
at org.hibernate.cfg.HbmBinder.bindRootPersistentClassCommonValues(HbmBinder.java:343)
at org.hibernate.cfg.HbmBinder.bindRootClass(HbmBinder.java:282)
at org.hibernate.cfg.HbmBinder.bindRoot(HbmBinder.java:153)
at org.hibernate.cfg.Configuration.add(Configuration.java:386)
at org.hibernate.cfg.Configuration.addInputStream(Configuration.java:427)
at org.hibernate.cfg.Configuration.addResource(Configuration.java:482)
... 9 more
Caused by: java.lang.ClassNotFoundException: Event
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClassInternal(Unknown Source)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.hibernate.util.ReflectHelper.classForName(ReflectHelper.java:108)
at org.hibernate.util.ReflectHelper.reflectedPropertyClass(ReflectHelper.java:76)
... 17 more
Apparement il ne trouve pas mon fichier Events, hors mes fichiers se trouve comme ceci :
+events
Event
event.hbm.xml
hibernate.cfg.xml
si vous avez ue idée du pourquoi cet erreur ??