Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp
Hibernate version:
Mapping documents:
Code between sessionFactory.openSession() and session.close():
Full stack trace of any exception that occurs:
Name and version of the database you are using:
The generated SQL (show_sql=true):
Debug level Hibernate log excerpt:
i'm a newbie in tapestry and i have a problem that i dont find any solutions.
I'm using tapestry with hibernate in Eclipse.
My code using the hibernate Framework works but when i m using it with tapestry , i have the following message:
---------------------------------------------------------------------------------
org.apache.tapestry.ApplicationRuntimeException
Unable to invoke method verification on tutorial.EncoPers@167c5e3[EncoPers]: null
java.lang.reflect.InvocationTargetException
java.lang.NoClassDefFoundError
org/hibernate/Session
Stack Trace:
tutorial.EncoPers.verification(EncoPers.java:44)
sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
java.lang.reflect.Method.invoke(Unknown Source)
org.apache.tapestry.listener.ListenerMap.invokeTargetMethod(ListenerMap.java:301)
org.apache.tapestry.listener.ListenerMap.access$100(ListenerMap.java:87)
org.apache.tapestry.listener.ListenerMap$SyntheticListener.invoke(ListenerMap.java:141)
org.apache.tapestry.listener.ListenerMap$SyntheticListener.actionTriggered(ListenerMap.java:146)
org.apache.tapestry.form.Form.renderComponent(Form.java:454)
org.apache.tapestry.AbstractComponent.render(AbstractComponent.java:896)
org.apache.tapestry.form.Form.rewind(Form.java:604)
org.apache.tapestry.engine.RequestCycle.rewindForm(RequestCycle.java:475)
org.apache.tapestry.form.Form.trigger(Form.java:618)
org.apache.tapestry.engine.DirectService.service(DirectService.java:203)
org.apache.tapestry.engine.AbstractEngine.service(AbstractEngine.java:879)
org.apache.tapestry.ApplicationServlet.doService(ApplicationServlet.java:238)
org.apache.tapestry.ApplicationServlet.doPost(ApplicationServlet.java:367)
javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:667)
org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
java.lang.Thread.run(Unknown Source)
-------------------------------------------------------------
package MyHibernate;
import org.hibernate.*;
import org.hibernate.cfg.*;
public class HibernateUtil {
public static final SessionFactory sessionFactory;
static {
try {
// Create the SessionFactory from 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 Session currentSession() throws HibernateException {
Session s = (Session) session.get();
// Open a new Session, if this thread has none yet
if (s == null) {
s = sessionFactory.openSession();
// Store it in the ThreadLocal variable
session.set(s);
}
return s;
}
public static void closeSession() throws HibernateException {
Session s = (Session) session.get();
if (s != null)
s.close();
session.set(null);
}
}
import org.apache.tapestry.IAsset;
import org.apache.tapestry.IRequestCycle;
import org.apache.tapestry.html.BasePage;
import org.hibernate.Session;
import org.hibernate.Transaction;
import Hibernation.TPersonne;
import MyHibernate.HibernateUtil;
import MyHibernate.Manager;
public class EncoPers extends BasePage {
private String nom = null;
private String prenom = null;
private String email = null;
private String mot = null;
private String error = "";
public void detach() {
error = "";
super.detach();
}
public boolean getHasError() {
if ((error == null) || (error.length() == 0)) {
return (false);
}
return (true);
}
public String getError() {
return error;
}
public void test (IRequestCycle cycle)
{
nom ="";
prenom="";
}
public void verification(IRequestCycle cycle)
{
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
TPersonne monClient = new TPersonne();
monClient.setPrsNom(nom);
monClient.setPrsPrenom(prenom);
monClient.setPrsEmail(email);
session.save(monClient);
tx.commit();
HibernateUtil.sessionFactory.close();
//cycle.activate("Success");
}
//Retrieve the appropriate asset for the
//number of wrong guesses
public IAsset getGuessImageAsset() {
return null;
}
public String getMot() {
return mot;
}
public void setMot(String mot) {
this.mot = mot;
}
public String getEmail() {
return email;
}
public void setEmail(String datenaiss) {
this.email = datenaiss;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getPrenom() {
return prenom;
}
public void setPrenom(String prenom) {
this.prenom = prenom;
}
}
Thanks in advance.
phaus