prb de connexion de hibernate
Bonsoir
J ai fait une petite application en jsf + Hibernate
Et j ai fait une interface qui traite l ajout d un utilisateur et voici le code de ma page index.jsp
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
|
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h" %>
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<f:view>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Identification</title>
</head>
<body>
<h:form id="form1">
<h:outputText value="login"/>
<h:inputText id="login" value="#{traitement.login}" styleClass="input" >
</h:inputText>
<br>
<br>
<h:outputText value="MDP" />
<h:inputText id="mdp" value="#{traitement.mdp}" styleClass="input" >
</h:inputText>
<br>
<br>
<div align="center">
<h:commandButton action="#{traitement.Ajout}" value="Ajouter" />
<h:commandButton value="Annuler"/>
</div>
</h:form>
</body>
</f:view>
</html> |
Et voici le code de mon bean
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 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
|
package Traitement;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.Map;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.directory.BasicAttribute;
import javax.naming.directory.BasicAttributes;
import javax.naming.directory.DirContext;
import javax.naming.directory.InitialDirContext;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import com.projet.User;
import com.sun.org.apache.bcel.internal.classfile.Attribute;
import com.sun.org.apache.xalan.internal.xsltc.runtime.Attributes;
import com.util.HibernateUtil;
import org.hibernate.*;
import javax.faces.context.FacesContext;
import javax.faces.event.ActionEvent;
import javax.faces.model.SelectItem;
import javax.servlet.http.HttpServletRequest;
import com.projet.UserHome;
public class traitement {
private Integer id;
private String mdp;
private String login;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getMdp() {
return mdp;
}
public void setMdp(String mdp) {
this.mdp = mdp;
}
public String getLogin() {
return login;
}
public void setLogin(String login) {
this.login = login;
}
public String Ajout() throws HibernateException{
System.out.println("Debut Ajout");
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User u1= new User();
u1.setLogin(getLogin());
System.out.println("login"+getLogin());
u1.setMdp(getMdp());
System.out.println("MDP"+getMdp());
session.save(u1);
session.getTransaction().commit();
HibernateUtil.getSessionFactory().close();
System.out.println("Fin Ajout");
return "ajouter";
}
public static void main(String[] args) throws Exception{
traitement t=new traitement();
t.Ajout();
}
} |
Et voici le code de mon faces-config.xml
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
<?xml version="1.0"?>
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.1//EN"
"http://java.sun.com/dtd/web-facesconfig_1_1.dtd">
<faces-config>
<managed-bean>
<managed-bean-name>traitement</managed-bean-name>
<managed-bean-class>Traitement.traitement</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
</faces-config> |
Et qd j exécute mon code de bean avec main se trouvant a mon bean : traitement.java ça marche bien l ajout mais j exécute mon code au niveau de ma page index.jsp voici les erreurs :
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 59 60 61 62 63 64 65 66 67 68 69 70 71
|
description Le serveur a rencontré une erreur interne () qui l'a empêché de satisfaire la requête.
exception
javax.servlet.ServletException: #{traitement.Ajout}: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
javax.faces.webapp.FacesServlet.service(FacesServlet.java:209)
cause mère
javax.faces.FacesException: #{traitement.Ajout}: javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:78)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
cause mère
javax.faces.el.EvaluationException: java.lang.ExceptionInInitializerError
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:130)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
cause mère
java.lang.ExceptionInInitializerError
com.util.HibernateUtil.<clinit>(HibernateUtil.java:16)
Traitement.traitement.Ajout(traitement.java:80)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197)
cause mère
java.lang.NoSuchMethodError: org.apache.log4j.Logger.isTraceEnabled()Z
org.slf4j.impl.Log4jLoggerAdapter.isTraceEnabled(Log4jLoggerAdapter.java:81)
org.hibernate.type.NullableType.<clinit>(NullableType.java:59)
org.hibernate.Hibernate.<clinit>(Hibernate.java:103)
org.hibernate.type.TypeFactory.<clinit>(TypeFactory.java:69)
org.hibernate.mapping.SimpleValue.getType(SimpleValue.java:283)
org.hibernate.mapping.SimpleValue.isValid(SimpleValue.java:276)
org.hibernate.mapping.Property.isValid(Property.java:207)
org.hibernate.mapping.PersistentClass.validate(PersistentClass.java:458)
org.hibernate.mapping.RootClass.validate(RootClass.java:215)
org.hibernate.cfg.Configuration.validate(Configuration.java:1149)
org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1334)
com.util.HibernateUtil.<clinit>(HibernateUtil.java:12)
Traitement.traitement.Ajout(traitement.java:80)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
java.lang.reflect.Method.invoke(Method.java:585)
com.sun.faces.el.MethodBindingImpl.invoke(MethodBindingImpl.java:126)
com.sun.faces.application.ActionListenerImpl.processAction(ActionListenerImpl.java:72)
javax.faces.component.UICommand.broadcast(UICommand.java:312)
javax.faces.component.UIViewRoot.broadcastEvents(UIViewRoot.java:267)
javax.faces.component.UIViewRoot.processApplication(UIViewRoot.java:381)
com.sun.faces.lifecycle.InvokeApplicationPhase.execute(InvokeApplicationPhase.java:75)
com.sun.faces.lifecycle.LifecycleImpl.phase(LifecycleImpl.java:200)
com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:90)
javax.faces.webapp.FacesServlet.service(FacesServlet.java:197) |
Est-ce que je dois ajouter qlq choses et merci d avance ??