Bonjour a tous,
j'essaie de me connecter a ma base de données avec Hibernate ... en vain.
Voici les informations :
Hibernate version: 3.0.5
Mapping documents: Administrateur.hbm.xml
Code:
<?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="be.cityform.administration.domain.Administrateur" table="administrateur">
<id name="id" column="id_admin" type="java.lang.Integer" access="field">
<generator class="identity"/>
</id>
<property name="login" column="identifiant" type="java.lang.String" />
<property name="password" column="password" type="java.lang.String" />
<property name="nom" column="nom" type="java.lang.String" />
<property name="prenom" column="prenom" type="java.lang.String" />
</class>
</hibernate-mapping>
HibernateSessionFactory.java :Code:
package be.cityform.administration.utils;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;
public class HibernateSessionFactory {
private static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory
sessionFactory = new Configuration().configure().buildSessionFactory();
} catch (Throwable ex) {
throw new ExceptionInInitializerError(ex);
}
}
public static final ThreadLocal session = new ThreadLocal();
public static Session currentSession() {
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() {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}
}
Exception :Code:
[b][u]description[/b][/u] The server encountered an internal error () that prevented it from fulfilling this request.
[b][u]exception[/b][/u]
javax.servlet.ServletException: Servlet execution threw an exception
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
[b][u]root cause[/b][/u]
java.lang.ExceptionInInitializerError
be.cityform.administration.utils.HibernateSessionFactory.<clinit>(HibernateSessionFactory.java:21)
be.cityform.administration.HibernateTest.doGet(HibernateTest.java:21)
javax.servlet.http.HttpServlet.service(HttpServlet.java:697)
javax.servlet.http.HttpServlet.service(HttpServlet.java:810)
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:81)
Name and version of the database you are using:Postgressql 7.4
Servlet de testCode:
package be.cityform.administration;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.hibernate.Session;
import org.hibernate.Transaction;
import be.cityform.administration.domain.Administrateur;
import be.cityform.administration.utils.HibernateSessionFactory;
public class HibernateTest extends HttpServlet {
private static final long serialVersionUID=0;
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
Session session = HibernateSessionFactory.currentSession();
Transaction tx = session.beginTransaction();
Administrateur admin0 = new Administrateur(0,"test1","test2","test3","test4");
session.save(admin0);
tx.commit();
HibernateSessionFactory.closeSession();
}
}
Merci d'avance car ca fait des heures que je suis sur le problème ...