aspose file tools*
The moose likes Other Application Frameworks and the fly likes Tapestry Hibernate / session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Other Application Frameworks
Bookmark "Tapestry Hibernate / session" Watch "Tapestry Hibernate / session" New topic
Author

Tapestry Hibernate / session

Phauderel Phaus
Greenhorn

Joined: Jan 25, 2006
Posts: 1
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
Martijn Dashorst
author
Ranch Hand

Joined: Jan 23, 2006
Posts: 58
Originally posted by Phauderel Phaus:
[QB]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.NoClassDefFoundError
org/hibernate/Session
Stack Trace:
tutorial.EncoPers.verification(EncoPers.java:44)
[/QOUTE]

I don't know how you run your web application, perhaps with the webtools server integration, or with the sysdeo tomcat plugin. But this error tells me that you don't have the hibernate package on your web application classpath.

The servlet container (the application server) uses a different classloader for running your web applciation. The eclipse plugin running your application needs to know which libraries to use, and it doesn't know about Hibernate. Hence you get the NoClassDefFoundError.

I strongly suggest you download the Jetty application server, unzip it to your c:\ folder, and install the Jetty launcher plugin into eclipse. Then create a Jetty launch configuration and run your application that way. You will get instant gratification, as the launcher plugin puts your whole project classpath (including dependencies) in the webapp classloader.

It is cheating a bit, but it makes development much easier.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Tapestry Hibernate / session