hibernate + mysql + tomcat
Bonjour,
J'ai une erreur d'éxécution que j'arrive pas a resoudre vu ke je suis debutant ds se domaine.
l'erreur est la suivante :
Code:
1 2 3 4 5 6 7
| Initial SessionFactory creation failed.java.lang.NoClassDefFoundError: org/dom4j/Attribute
Exception in thread "main" java.lang.ExceptionInInitializerError
at istia.st.springmvc.personnes.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:17)
at Test.main(Test.java:9)
Caused by: java.lang.NoClassDefFoundError: org/dom4j/Attribute
at istia.st.springmvc.personnes.hibernate.HibernateUtil.<clinit>(HibernateUtil.java:13)
... 1 more |
je vous donne les principaux fichiers qui interviennent, c'est trop long je sais ,si vous avez un peu de temps jetez un coup d'oeuil
merci
ma classe de test est :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13
| import java.util.*;
import net.sf.hibernate.*;
import istia.st.springmvc.personnes.hibernate.*;
public class Test {
public static void main(String[] args)
throws HibernateException {
Session s = HibernateUtil.currentSession();
HibernateUtil.closeSession();
System.exit(0);
}
} |
ma classe HibernateUtil est :
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
| public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory
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 Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this Thread has none yet
if (s == null) {
s = sessionFactory.openSession();
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
session.set(null);
if (s != null)
s.close();
}
} |
mon fichier hibernate.cfg.xml est
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
| <?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE hibernate-configuration
PUBLIC "-//Hibernate/Hibernate Configuration DTD//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-2.0.dtd">
<hibernate-configuration>
<session-factory>
<!-- local connection properties -->
<property name="hibernate.connection.url">
jdbc:mysql://localhost/dbpersonnes
</property>
<property name="hibernate.connection.driver_class">
com.mysql.jdbc.Driver
</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password" />
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for MySQL -->
<property name="dialect">
net.sf.hibernate.dialect.MySQLDialect
</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.use_outer_join">true</property>
<property name="hibernate.transaction.factory_class">
net.sf.hibernate.transaction.JTATransactionFactory
</property>
<property name="jta.UserTransaction">
java:comp/UserTransaction
</property>
<mapping resource="Personnes.hbm.xml" />
</session-factory>
</hibernate-configuration> |
et finalement mon fichier hbm est
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 53 54 55 56 57 58
| <?xml version="1.0"?>
<!DOCTYPE hibernate-mapping PUBLIC
"-//Hibernate/Hibernate Mapping DTD//EN"
"http://hibernate.sourceforge.net/hibernate-mapping-2.0.dtd" >
<hibernate-mapping package="istia.st.springmvc.personnes.hibernate">
<class name="Personnes" table="personnes">
<id
column="ID"
name="Id"
type="integer"
>
<generator class="increment"/>
</id>
<property
column="VERSION"
length="11"
name="Version"
not-null="false"
type="integer"
/>
<property
column="DATENAISSANCE"
length="10"
name="Datenaissance"
not-null="false"
type="date"
/>
<property
column="NOM"
length="20"
name="Nom"
not-null="false"
type="string"
/>
<property
column="PRENOM"
length="20"
name="Prenom"
not-null="false"
type="string"
/>
<property
column="NBENFANTS"
length="11"
name="Nbenfants"
not-null="false"
type="integer"
/>
<property
column="MARIE"
length="11"
name="Marie"
not-null="false"
type="integer"
/>
</class>
</hibernate-mapping> |