premier exemple hibernate: org.hibernate.MappingException
Bonjour à tous,
Je debute avec hibernate j ai trouvé plusieur problème avec mon premier test d hibernate synchroniser.
J’utilise hibernate 3 et eclipse 3.2 et la base de donnes mySQL ,Je suis le fameux tutoriel de ce club.pour plus de precisient je vous montre mes fichiers de configuration :
hibernate.cfg.xml
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
|
<?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 >
<!-- local connection properties -->
<property name="hibernate.connection.url">jdbc:mysql://aroua/arwa</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.connection.password">1allah</property>
<!-- property name="hibernate.connection.pool_size"></property -->
<!-- dialect for MySQL -->
<property name="dialect">org.hibernate.dialect.MySQLDialect</property>
<!-- Enable Hibernate's automatic session context management -->
<property name="current_session_context_class">thread</property>
<property name="hibernate.show_sql">false</property>
<property name="hibernate.transaction.factory_class">org.hibernate.transaction.JDBCTransactionFactory</property>
</session-factory>
</hibernate-configuration> |
puis le fichier hibernateUtil.java:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
|
package com.test.hibernate;
import org.hibernate.*;
import org.hibernate.cfg.*;
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;
}
} |
et la classe Test2.java qui contient la fct main:
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
public class Test2 {
public static void main(String[] args) throws HibernateException {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
Emp emp = new Emp();
emp.setNom("akkari");
emp.setPrenom("kawthar");
session.save(emp);
}
} |
A l’execution j obtiens le message d’erreur suivant :
:aie:
16:04:21,526 INFO SessionFactoryObjectFactory:82 - Not binding factory to JNDI, no JNDI name configured
Exception in thread "main" org.hibernate.MappingException: Unknown entity: com.test.hibernate.Emp:aie:
Si quelqu’un peux m’aider je serais vraiment reconnaisante.:king: