-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 
Author Message
 Post subject: hibernate Tapestry session
PostPosted: Wed Jan 25, 2006 4:26 am 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
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


Top
 Profile  
 
 Post subject: classpath
PostPosted: Wed Jan 25, 2006 3:13 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
It is confusing but java.lang.NoClassDefFoundError means that class org.hibernate.Session cannot find other classes it needs to get instantiated. Unfortunately JVM does not provide more details (although it could).

The solution: make sure that all the necessary Hibernate related jars are available in the classpath.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 5:34 pm 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
I'm using Eclipse and i have put in the "java build path" all the library available in the folder lib of hibernate.
I have still the same problem.

What can i do ? i'm desperated.

Thanks in advance.

phaus


Top
 Profile  
 
 Post subject: eclipse
PostPosted: Wed Jan 25, 2006 6:26 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I do not use eclipse (I am happy IDEA user) therefore cannot speak authoritatively, but I suspect that runtime classpath is different than you build path.

I guess start a web-container from within eclipse and you need to make sure that the container has all the necessary libraries in its classpath and/or sees them as webapp libraries under WEB-INF/lib

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 25, 2006 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Is your build path the WEB_INF/lib directory that is used for deployment?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 4:12 pm 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
You will find herewith the build xml.

i have a headache. That made two weeks that I seek a solution.

Please help me.


Thanks in advance


build.xml
---------------------------
<?xml version="1.0"?>
<project name="ServletDeploy" default="Build_All">
<!--
This ANT script does NOT compile the application,
we are relying on Eclipse to do all Java compilation.
This script merely deploys the application to Tomcat.

This script will work with Tomcat 4.0, but Tapestry
says it requires Tomcat 4.1, so make sure you have
Tomcat 4.1 running.

You will need Tomcat manager running and working
login for Tomcat manager. To create a user for
Tomcat manager, edit the file

<tomcat>\conf\tomcat-users.xml

and add a line for the desired user, such as

<user
username="username"
password="password"
fullName="Your Fullname"
roles="manager"/>

If it is not already there, you may want a to add
the manager role above the user line... such as

<role rolename="manager"/>

This script was designed to deploy a Tapestry servlet
application using Tomcat 4.1+. This script assumes
that the project is laid out how Spindle lays out
applications. All that should need to be modified
is the few lines near the top...

application
tomcatHome
workspaceHome
mgrUsername
mgrPassword

Using the manager to install/remove applications keeps
you from having to stop and restart Tomcat every time
you need to update your application.
-->
<property name="application" value="PersonneVoiture2" />
<property name="tomcatHome" value="C:/Program Files/Apache Software Foundation/Tomcat 5.5" />
<property name="workspaceHome" value="d:/eclipse/workspace" />
<property name="mgrUsername" value="admin" />
<property name="mgrPassword" value="" />

<property name="webappsHome" value="${tomcatHome}/webapps" />
<property name="appHome" value="${webappsHome}/${application}" />
<property name="contextHome" value="${workspaceHome}/${application}/context" />
<property name="deployWarsDir" value="${workspaceHome}/${application}/DeployWars" />
<property name="mgrUrl" value="http://localhost:8080/manager" />
<property name="mgrRemoveUrl" value="${mgrUrl}/remove" />
<property name="mgrDeployUrl" value="${mgrUrl}/install" />

<target name="Deploy_to_LocalDev">
<!-- LocalDev deploys right into the local tomcat -->
<mkdir dir="${deployWarsDir}/local-dev" />
<delete file="${deployWarsDir}/local-dev/${application}.war" />
<war
duplicate="preserve"
destfile="${deployWarsDir}/local-dev/${application}.war"
webxml="${contextHome}/WEB-INF/web.xml">
<classes dir="${contextHome}/WEB-INF/classes" />
<fileset dir="${contextHome}">
<include name="*" />
<include name="css/*.css" />
<include name="images/*" />
<include name="WEB-INF/*.page" />
<include name="WEB-INF/*.application" />
<include name="WEB-INF/*.jwc" />
<include name="WEB-INF/*.html" />
</fileset>
</war>

<!-- Deploy to Tomcat 4.1 -->
<!-- NOTE: The remaineder of this installation requires the Tomcat 4.0+
manager be running and the build will fail if it is not. -->
<!-- Remove the application -->
<delete file="deploy-local-remove.txt" />
<get
src="${mgrRemoveUrl}?path=/${application}"
dest="deploy-local-remove.txt"
username="${mgrUsername}"
password="${mgrPassword}" />
<loadfile property="deploy.local.remove.result"
srcFile="deploy-local-remove.txt" />
<echo>${deploy.local.remove.result}</echo>
<delete file="deploy-local-remove.txt" />

<!-- Remove the directory containing the old version of the application -->
<!--
<delete dir="${webappsHome}/${application}" />
-->
<unzip
src="${deployWarsDir}/local-dev/${application}.war"
dest="${webappsHome}/${application}" />

<!-- Install the application -->
<delete file="deploy-local-remove.txt" />
<property name="mgrDeployParams"
value="path=/${application}&amp;war=file://${webappsHome}/${application}/" />
<!-- <get
src="${mgrDeployUrl}?${mgrDeployParams}"
dest="deploy-local-remove.txt"
username="${mgrUsername}"
password="${mgrPassword}" />
<loadfile property="deploy.local.remove.resultb"
srcFile="deploy-local-remove.txt" />
<echo>${deploy.local.remove.resultb}</echo>
<delete file="deploy-local-remove.txt" />-->
</target>

<target name="Build_All" depends="Deploy_to_LocalDev" />

</project>


Top
 Profile  
 
 Post subject: chaeck war file content
PostPosted: Thu Jan 26, 2006 4:45 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
I do not see lib element in the war task.

For simplicity sake:
- stop tomcat;
- create directory ${tomcat_home}/webapps/app;
- unzip content of your war file there and make sure it has all the necessary libraries;
- start tomcat and check if everything works;

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 26, 2006 4:59 pm 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
Sorry but i dont understand. Where i must create exactly the directory ${tomcat_home}/webapps/app, and how i can unzip a content of a war file?

Phaus


Top
 Profile  
 
 Post subject: ...
PostPosted: Thu Jan 26, 2006 5:50 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
${tomcat_home} stands for rott directory where you have tomcat installed,

war file is simply zip file so WinZip or something alike can be used to unzip war files. or jar command can be used
jar -xf war-file-name.war

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jan 27, 2006 4:16 am 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
i have just carried out your procedure. In the Web-inf in the repertory webapps of Tomcat there are no librarys which are added.
How to add them manually or which codes must I put in my buil.xml (file of deployment)?

Thank you for your assistance

Phaus


Top
 Profile  
 
 Post subject: ant
PostPosted: Fri Jan 27, 2006 1:40 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
Please consult Ant manual:
http://ant.apache.org/manual/index.html
for guidance on writing you build.xml file, as I mentioned yors seems to miss lib instructions in war task

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 29, 2006 6:33 am 
Newbie

Joined: Thu Sep 29, 2005 1:20 pm
Posts: 16
Location: Brussel
first of all, i would like to thank so much Kgignatyev for his great help and his patience.

I solve this problem by including in my web-inf\lib the libraries of hibernate and the connector to my DB.

After that i had another problem in my class managing the hibernate framework. This class had a static loading in it. That wasn't accepted by tomcat.



Once again Thanks to Kgignatyev

_________________
Phaus
Java Developper


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 12 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.