Bonjour,
j'arrive pas a faire marcher hibernate, voila l'erreur ki me donne :
javax.servlet.ServletException: org.hibernate.HibernateException: No CurrentSessionContext configured!
org.apache.struts.action.RequestProcessor.processException(RequestProcessor.java:535)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:433)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
cause m�re
org.hibernate.HibernateException: No CurrentSessionContext configured!
org.hibernate.impl.SessionFactoryImpl.getCurrentSession(SessionFactoryImpl.java:542)
com.hibernate.utils.FindUser.getInfoUser(FindUser.java:21)
action.struts.LoginAction.execute(LoginAction.java:31)
org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:431)
org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:236)
org.apache.struts.action.ActionServlet.process(ActionServlet.java:1196)
org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
voici ma configuration :
le fichier hibernate.cfg.xml
<?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.dialect">org.hibernate.dialect.MySQLDialect</property>
<property name="hibernate.connection.driver_class">com.mysql.jdbc.Driver</property>
<property name="hibernate.connection.url">jdbc:mysql://localhost:3306/yassine</property>
<property name="hibernate.connection.username">root</property>
<mapping resource="client.hbm.xml"/>
</session-factory>
</hibernate-configuration>
le fichier HibernateUtil.java
package com.hibernate.utils;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import org.hibernate.cfg.AnnotationConfiguration;
import org.hibernate.SessionFactory;
/**
* Hibernate Utility class with a convenient method to get Session Factory object.
*
* @author yassinert
*/
public class HibernateUtil {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from standard (hibernate.cfg.xml)
// config file.
sessionFactory = new AnnotationConfiguration().configure().buildSessionFactory();
} catch (Throwable ex) {
// Log the exception.
System.err.println("Initial SessionFactory creation failed." + ex);
throw new ExceptionInInitializerError(ex);
}
}
public static SessionFactory getSessionFactory() {
return sessionFactory;
}
}
Le fichier FindUser.java
package com.hibernate.utils;
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
import java.util.Iterator;
import org.hibernate.*;
import objets.User;
/**
*
* @author yassinert
*/
public class FindUser {
public User getInfoUser(String _login, String _password)throws HibernateException{
User user =new User();
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
String query = "select c.nom, c.prenom from client c where c.login='" + _login + "' and c.passe='"+ _password +"'";
Iterator results = session.createSQLQuery(query).list().iterator();
String nom=null;
String prenom=null;
while(results.hasNext())
{
Object[] row = (Object[]) results.next();
nom = (String) row[0];
prenom = (String) row[1];
}
user.setNom(nom);
user.setPrenom(prenom);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
return user;
}
Configuration: Windows XP Internet Explorer 7.0