pbl failed.org.hibernate.MappingException: entity class not found: User
la classe User et User.hbm.xml sont pourtant dans le meme package.
User.hbm.xml:
Code:
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">
<!-- Generated 10 juin 2010 12:39:25 by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="User" table="user" catalog="mabasse">
<id name="idUser" type="java.lang.Integer">
<column name="id_user" />
<generator class="increment" />
</id>
<property name="loginUser" type="string">
<column name="login_user" length="25" not-null="true" />
</property>
<property name="passwordUser" type="string">
<column name="password_user" length="25" not-null="true" />
</property>
</class>
</hibernate-mapping> |
pbl Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured
classe User
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package com.map;
import org.hibernate.*;
import com.util.HibernateUtil;
import com.util.*;
public class testInsert {
public static void main(String[] args)
throws HibernateException {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User user = new User();
user.setLoginUser("wfh");
user.setPasswordUser("wfh");
session.save(user);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
}
} |
User.hbm.xml
Code:
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">
<!-- Generated 10 juin 2010 12:39:25 by Hibernate Tools 3.2.4.GA -->
<hibernate-mapping>
<class name="com.map.User" table="user" catalog="mabasse">
<id name="idUser" type="java.lang.Integer">
<column name="id_user" />
<generator class="increment" />
</id>
<property name="loginUser" type="string">
<column name="login_user" length="25" not-null="true" />
</property>
<property name="passwordUser" type="string">
<column name="password_user" length="25" not-null="true" />
</property>
</class>
</hibernate-mapping> |
hibernate.config.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
| <?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>
<property name="hibernate.bytecode.use_reflection_optimizer">false</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.password">123</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/mabasse</property>
<property name="hibernate.connection.username">root</property>
<property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
<mapping resource="com/map/User.hbm.xml" />
</session-factory>
</hibernate-configuration> |
hibernate util
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
| package com.util;
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;
}
} |
Lorsque j'execute ce main
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
| package com.map;
import org.hibernate.*;
import com.util.HibernateUtil;
import com.util.*;
public class testInsert {
public static void main(String[] args)
throws HibernateException {
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User user = new User();
user.setLoginUser("wfh");
user.setPasswordUser("wfh");
session.save(user);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
}
} |
j'ai l'erreure
Code:
1 2 3
| Exception in thread "main" org.hibernate.HibernateException: No CurrentSessionContext configured!
at org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:696)
at com.map.testInsert.main(testInsert.java:11) |
Désolais pour vous soliciter autant je suis nouveau en hibernate