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.  [ 9 posts ] 
Author Message
 Post subject: Hep with hibernate in eclipse
PostPosted: Mon May 14, 2007 6:23 am 
Newbie

Joined: Mon May 14, 2007 6:19 am
Posts: 5
hi,

I am a newbie, trying to learn struts and hibernate. I am using eclipse IDE with sysdeo tomcat plugin. I have created a small sample web application using struts successfully.I created this using a Tomcat project in Eclipse. I then created another project (this time a java project) in the same eclipse workspace and created a sample hibernate application. Now i wish to integrate the two, i.e. my struts application should talk to the database via hibernate. For this i included the hibernate project in the build path of the struts project and made the call. The code was compiled successfully. However when i try to run the web application, i get a NoClassDefFoundError. I think somehow the path of the hibernate application needs to be set at runtime in the web application. Any idea how this can be done in eclipse?
Any help would be much appreciated. Thanks in advance.


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 14, 2007 5:36 pm 
Newbie

Joined: Mon May 14, 2007 10:24 am
Posts: 1
Location: Delhi, India
Check few things as follows:-
1) Struts project must have your hibernate project reference under .classpath file
<classpathentry combineaccessrules="false" kind="src" path="/your hibernate project"/>
2) Hiberante project must have all jars under .classpath file
<classpathentry kind="lib" path="/your struts project/WebRoot/WEB-INF/lib/hibernate3.jar"/>

If still you found same problem then please give your exception message with exact noclassfound.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:25 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
resh123, rajeevkumar,

one thing to note here is that it's NoClassDefFoundError and not Exception, this error is severe than exception the class might be in class path but its not getting loaded under same JVM.

resh123,
make sure that hibernate classes are under WEB-INF/classes or lib folder, try to run whole application without eclipse and see any changes.... some times the java application runs under JVM started by eclipse and not the server you are running.

alternatively you can put all hibernate and struts classes in one jar file ... and if that doesn't helps try adding hibernate class file entry in MANIFEST file of your jar..

_________________
Hope this helps... :)

Regards,

Rohit

--Don'f forget to rate...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:29 am 
Newbie

Joined: Mon May 14, 2007 6:19 am
Posts: 5
Thanks for the response. However it still does not work.
The following is the code in the action class of the struts project:

package minihr.actions;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import testa.TestAccess;
import testa.User;


import org.apache.struts.action.*;

public class LoginAction extends Action{

public ActionForward execute (ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {

boolean success = User.authenticate();
return (mapping.findForward("success"));

}

}

Here, User is a class in the hibernate codebase. Its code is:

package testa;

import org.hibernate.Session;
import util.HibernateUtil;

public class User {

public static boolean authenticate()
{
Session session = HibernateUtil.getSessionFactory().getCurrentSession();
session.beginTransaction();
User user = new User();
try
{
session.load(user, "resh");
}
catch (Exception e ) {
System.out.println("User NOT found");
return false;
}
session.getTransaction().commit();
return true;
}
}

Following is the classpath file if the struts project:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry combineaccessrules="false" kind="src" path="/MiniHRDatabase"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="src" path="WEB-INF/src"/>
<classpathentry output="work" kind="src" path="work"/>
<classpathentry kind="lib" path="WEB-INF/lib/antlr-2.7.2.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/commons-beanutils-1.7.0.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/commons-chain-1.1.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/commons-digester-1.8.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/commons-validator-1.3.1.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/oro-2.0.8.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/struts-core-1.3.8.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/struts-taglib-1.3.8.jar"/>
<classpathentry kind="lib" path="WEB-INF/lib/struts-tiles-1.3.8.jar"/>
<classpathentry kind="var" path="TOMCAT_HOME/common/lib/servlet.jar"/>
<classpathentry kind="var" path="TOMCAT_HOME/common/lib/jasper-runtime.jar"/>
<classpathentry exported="true" kind="lib" path="/MiniHRDatabase/bin"/>
<classpathentry kind="output" path="WEB-INF/classes"/>
</classpath>


Following is the classpath file of the hibernate project:

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
<classpathentry kind="lib" path="lib/Access_JDBC30.jar"/>
<classpathentry kind="lib" path="lib/antlr-2.7.6.jar"/>
<classpathentry kind="lib" path="lib/asm.jar"/>
<classpathentry kind="lib" path="lib/asm-attrs.jar"/>
<classpathentry kind="lib" path="lib/cglib-2.1.3.jar"/>
<classpathentry kind="lib" path="lib/commons-collections-2.1.1.jar"/>
<classpathentry kind="lib" path="lib/commons-logging-1.0.4.jar"/>
<classpathentry kind="lib" path="lib/dom4j-1.6.1.jar"/>
<classpathentry kind="lib" path="lib/hibernate.zip"/>
<classpathentry kind="lib" path="lib/hibernate3.jar"/>
<classpathentry kind="lib" path="lib/jdbc2_0-stdext.jar"/>
<classpathentry kind="lib" path="lib/jta.jar"/>
<classpathentry kind="lib" path="lib/log4j-1.2.11.jar"/>
<classpathentry kind="lib" path="lib/xml-apis.jar"/>
<classpathentry kind="lib" path="dtd"/>
<classpathentry kind="output" path="bin"/>
</classpath>


Following is the exception i get:
javax.servlet.ServletException: Servlet execution threw an exception
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:269)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)


root cause

java.lang.NoClassDefFoundError: org/hibernate/ObjectNotFoundException
at minihr.actions.LoginAction.execute(LoginAction.java:33)
at org.apache.struts.chain.commands.servlet.ExecuteAction.execute(ExecuteAction.java:58)
at org.apache.struts.chain.commands.AbstractExecuteAction.execute(AbstractExecuteAction.java:67)
at org.apache.struts.chain.commands.ActionCommandBase.execute(ActionCommandBase.java:51)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.commons.chain.generic.LookupCommand.execute(LookupCommand.java:304)
at org.apache.commons.chain.impl.ChainBase.execute(ChainBase.java:190)
at org.apache.struts.chain.ComposableRequestProcessor.process(ComposableRequestProcessor.java:283)
at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
at org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:462)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:760)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:260)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2415)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:172)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:641)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline$StandardPipelineValveContext.invokeNext(StandardPipeline.java:643)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:480)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:995)
at org.apache.coyote.tomcat4.CoyoteAdapter.service(CoyoteAdapter.java:223)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:432)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:386)
at org.apache.tomcat.util.net.TcpWorkerThread.runIt(PoolTcpEndpoint.java:534)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:530)
at java.lang.Thread.run(Thread.java:536)



Please help!

Thanks is advance.



rajeevkumar wrote:
Check few things as follows:-
1) Struts project must have your hibernate project reference under .classpath file
<classpathentry combineaccessrules="false" kind="src" path="/your hibernate project"/>
2) Hiberante project must have all jars under .classpath file
<classpathentry kind="lib" path="/your struts project/WebRoot/WEB-INF/lib/hibernate3.jar"/>

If still you found same problem then please give your exception message with exact noclassfound.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:33 am 
Newbie

Joined: Mon May 14, 2007 6:19 am
Posts: 5
Rohit, thnx for ur reply. Do you mean to say that instead of separate projects, i should place both the hibernate code and the struts code in the same project in eclipse?
I have posted my code and all the details in a reply to rejeevkumar, can you please check it out and let me know if anything looks wrong?
Any help would be much appreciated.

Thanks.

Sagi wrote:
resh123, rajeevkumar,

one thing to note here is that it's NoClassDefFoundError and not Exception, this error is severe than exception the class might be in class path but its not getting loaded under same JVM.

resh123,
make sure that hibernate classes are under WEB-INF/classes or lib folder, try to run whole application without eclipse and see any changes.... some times the java application runs under JVM started by eclipse and not the server you are running.

alternatively you can put all hibernate and struts classes in one jar file ... and if that doesn't helps try adding hibernate class file entry in MANIFEST file of your jar..


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 1:33 am 
Newbie

Joined: Mon May 14, 2007 6:19 am
Posts: 5
Rohit, thnx for ur reply. Do you mean to say that instead of separate projects, i should place both the hibernate code and the struts code in the same project in eclipse?
I have posted my code and all the details in a reply to rejeevkumar, can you please check it out and let me know if anything looks wrong?
Any help would be much appreciated.

Thanks.

Sagi wrote:
resh123, rajeevkumar,

one thing to note here is that it's NoClassDefFoundError and not Exception, this error is severe than exception the class might be in class path but its not getting loaded under same JVM.

resh123,
make sure that hibernate classes are under WEB-INF/classes or lib folder, try to run whole application without eclipse and see any changes.... some times the java application runs under JVM started by eclipse and not the server you are running.

alternatively you can put all hibernate and struts classes in one jar file ... and if that doesn't helps try adding hibernate class file entry in MANIFEST file of your jar..


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 2:52 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
Quote:
Do you mean to say that instead of separate projects,i should place both the hibernate code and the struts code in the same project in eclipse?


Yes, this is what i mean to say, your code is getting compiles because jar files are available and visible to eclipse, but not to TOMCAT server,
put the hibernate jar file(+ your code) in WEB-INF/lib of server and run the application.

_________________
Hope this helps... :)

Regards,

Rohit

--Don'f forget to rate...


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:52 am 
Newbie

Joined: Mon May 14, 2007 6:19 am
Posts: 5
Thanks for the response. It did work :)
I kept the projects separate, however i added jaf file of the hibernate code and jars related to hibernate in the web-inf/lib folder of the struts application.
Thanks once again!


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 15, 2007 4:54 am 
Beginner
Beginner

Joined: Mon Nov 06, 2006 2:40 am
Posts: 29
Location: New Delhi, India
Please rate if it helped... :) Thanks


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 9 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.