-->
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.  [ 2 posts ] 
Author Message
 Post subject: WSAD5.0, EJB Session bean and Hibernate
PostPosted: Fri Mar 05, 2004 4:54 pm 
Newbie

Joined: Tue Feb 03, 2004 11:58 am
Posts: 11
Hi,
I have a problem implementing EJB session bean with Hibernate.
My web app is implemented in Struts 1.1. The LoginAction is invoked and
it succesfully looks up the HibernateTestHome, creates a remote interface
and calls doService() method that prints out success message indicating
that the session bean was succesfully looked up and created.

If I add Hibernate related code, I get an error message.

I need to mention that I have followed first 6 steps described in the
"Cookbook for running Hibernate in IBM WSAD 5.x" at
http://forum.hibernate.org/viewtopic.ph ... e+wsad+5+x

I did not setup DataSource and JAAS athentication becouse I would like to
use the info from hibernate.properties file.

My LoginAction looks like this:

package com.cot.ewwcms.web.struts;

import java.io.IOException;
import java.util.Hashtable;
import java.util.Locale;
import java.util.ArrayList;
import javax.servlet.*;//RequestDispatcher
import javax.servlet.ServletException;
import javax.servlet.http.*;//HttpServletRequest
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.util.MessageResources;
import com.cot.framework.core.BaseException;
import com.cot.framework.core.ArgumentList;
import com.cot.framework.service.Service;
import com.cot.framework.service.ServiceData;
import com.cot.framework.service.ServiceObjectFactory;
import com.cot.framework.web.struts.StrutsConverter;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.Properties;
import com.hibernate.blog.ejb.*;


/**
* Action class that implements the user logon.
*
* @author Cristian Calineac
* @since Februarie 18 2004
* @version $Revision: 1.0 $
*/

public class LogonAction extends Action {

/**
* The Struts Action Interface
*/
public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {

// Validate the request parameters specified by the user
ActionErrors errors = new ActionErrors();
String userId = ((LogonForm) form).getUserId();
String password = ((LogonForm) form).getPassword();

try {
// Create a service data object for this service
ArgumentList argList = new ArgumentList();
argList.setProperty("userId", userId);
argList.setProperty("password", password);

// Get the initial context
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "IIOP://localhost:2809");
props.put(Context.INITIAL_CONTEXT_FACTORY, "com.ibm.websphere.naming.WsnInitialContextFactory");
InitialContext initContext = new InitialContext(props);

InitialContext initial = new InitialContext(props);
Object objref = initial.lookup("ejb/com/hibernate/blog/ejb/HibernateTestHome");

HibernateTestHome home = (HibernateTestHome) PortableRemoteObject.narrow(objref, HibernateTestHome.class);
HibernateTest remote = home.create();
remote.doService();

// Set next page to main page
return (mapping.findForward("cma"));

} catch (BaseException be) {

be.printStackTrace();
// Map blf errors to action errors
StrutsConverter.convertErrorList(be.getErrorList(), errors);

// Set the errors so the next page can see them
saveErrors(request, errors);
// Return the input page to redisplay the form
return (new ActionForward(mapping.getInput()));

} catch (Exception e) {

e.printStackTrace();
// Create a general action error for the exception
errors.add(
ActionErrors.GLOBAL_ERROR,
new ActionError("GENERAL_SERVICE_ERROR"));
// Set the errors so the next page can see them
saveErrors(request, errors);
// Return the input page to redisplay the form
return (new ActionForward(mapping.getInput()));
}
}
}

and my HibernateTestBean looks like this:

package com.hibernate.blog.ejb;

import net.sf.hibernate.HibernateException;
import net.sf.hibernate.Session;
import net.sf.hibernate.SessionFactory;
import net.sf.hibernate.Transaction;
import net.sf.hibernate.cfg.Configuration;
import com.hibernate.blog.Blog;
import com.hibernate.blog.BlogItem;

/**
* Bean implementation class for Enterprise Bean: HibernateTest
*/
public class HibernateTestBean implements javax.ejb.SessionBean {
private javax.ejb.SessionContext mySessionCtx;

private SessionFactory _sessions;
/**
* doService
*/
public void doService() throws Exception {
System.out.println("HibernateTestBean.doService() called succesfully!");
}
/**
* getSessionContext
*/
public javax.ejb.SessionContext getSessionContext() {
return mySessionCtx;
}
/**
* setSessionContext
*/
public void setSessionContext(javax.ejb.SessionContext ctx) {
mySessionCtx = ctx;
try {
Configuration cfg = new Configuration();
cfg.addClass(com.hibernate.blog.Blog.class);
cfg.addClass(com.hibernate.blog.BlogItem.class);
_sessions = cfg.buildSessionFactory();
}
catch (Exception e) {
e.printStackTrace();
}
}
/**
* ejbCreate
*/
public void ejbCreate() throws javax.ejb.CreateException {
}
/**
* ejbActivate
*/
public void ejbActivate() {
}
/**
* ejbPassivate
*/
public void ejbPassivate() {
}
/**
* ejbRemove
*/
public void ejbRemove() {
}
}

The error message is:

[3/5/04 15:26:57:013 EST] 675fd904 ApplicationMg A WSVR0200I: Starting application: ewwcms_hibernateEAR
[3/5/04 15:26:57:138 EST] 675fd904 WebContainer A SRVE0169I: Loading Web Module: ewwcms.
[3/5/04 15:26:57:153 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: JSP 1.2 Processor: init
[3/5/04 15:26:58:013 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: SimpleFileServlet: init
[3/5/04 15:26:58:028 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: InvokerServlet: init
[3/5/04 15:26:58:122 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: action: init
[3/5/04 15:26:58:153 EST] 675fd904 PropertyMessa I org.apache.struts.util.PropertyMessageResources Initializing, config='org.apache.struts.util.LocalStrings', returnNull=true
[3/5/04 15:26:58:153 EST] 675fd904 PropertyMessa I org.apache.struts.util.PropertyMessageResources Initializing, config='org.apache.struts.action.ActionResources', returnNull=true
[3/5/04 15:26:58:747 EST] 675fd904 PropertyMessa I org.apache.struts.util.PropertyMessageResources Initializing, config='ApplicationResources', returnNull=true
[3/5/04 15:26:58:763 EST] 675fd904 EJBContainerI I WSVR0207I: Preparing to start EJB jar: hibernate_ejb.jar
[3/5/04 15:26:58:950 EST] 675fd904 EJBContainerI I WSVR0037I: Starting EJB jar: hibernate_ejb.jar
[3/5/04 15:26:58:997 EST] 675fd904 EJBContainerI E WSVR0040E: addEjbModule failed for hibernate_ejb.jar [class com.ibm.ws.runtime.component.DeployedModuleImpl]
java.lang.NoClassDefFoundError: net/sf/hibernate/cfg/Configuration
at java.lang.Class.newInstance0(Native Method)
at java.lang.Class.newInstance(Class.java:262)
at com.ibm.ejs.container.EJSContainer.loadBeanMetaData(EJSContainer.java:1275)
at com.ibm.ejs.container.EJSContainer.getHomeWrapperCommon(EJSContainer.java:958)
at com.ibm.ejs.container.EJSContainer.getHomeInstance(EJSContainer.java:881)
at com.ibm.ejs.container.EJSContainer.startBean(EJSContainer.java:860)
at com.ibm.ws.runtime.component.EJBContainerImpl.startBean(EJBContainerImpl.java:1249)
at com.ibm.ws.runtime.component.EJBContainerImpl.install(EJBContainerImpl.java:982)
at com.ibm.ws.runtime.component.EJBContainerImpl.start(EJBContainerImpl.java:1456)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:401)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.fireDeployedObjectStart(DeployedApplicationImpl.java:743)
at com.ibm.ws.runtime.component.DeployedModuleImpl.start(DeployedModuleImpl.java:337)
at com.ibm.ws.runtime.component.DeployedApplicationImpl.start(DeployedApplicationImpl.java:531)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.startApplication(ApplicationMgrImpl.java:254)
at com.ibm.ws.runtime.component.ApplicationMgrImpl.start(ApplicationMgrImpl.java:232)
at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:343)
at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:234)
at com.ibm.ws.runtime.component.ApplicationServerImpl.start(ApplicationServerImpl.java:117)
at com.ibm.ws.runtime.component.ContainerImpl.startComponents(ContainerImpl.java:343)
at com.ibm.ws.runtime.component.ContainerImpl.start(ContainerImpl.java:234)
at com.ibm.ws.runtime.component.ServerImpl.start(ServerImpl.java:182)
at com.ibm.ws.runtime.WsServer.start(WsServer.java:135)
at com.ibm.ws.runtime.WsServer.main(WsServer.java:232)
at java.lang.reflect.Method.invoke(Native Method)
at com.ibm.ws.bootstrap.WSLauncher.main(WSLauncher.java:94)
at com.ibm.etools.websphere.tools.runner.api.ServerRunnerV5$1.run(ServerRunnerV5.java:97)

[3/5/04 15:26:59:013 EST] 675fd904 EJBContainerI I WSVR0041I: Stopping EJB jar: hibernate_ejb.jar
[3/5/04 15:26:59:060 EST] 675fd904 EJBContainerI E WSVR0042E: Unable to stop ewwcms_hibernateEAR#hibernate_ejb.jar#HibernateTest: unknown bean home name - ewwcms_hibernateEAR#hibernate_ejb.jar#HibernateTest
[3/5/04 15:26:59:122 EST] 675fd904 EJBContainerI I WSVR0043E: Unbind failed for ejb/com/hibernate/blog/ejb/HibernateTestHome: name = ejb/com/hibernate/blog/ejb/HibernateTestHome: first name component of ejb/com/hibernate/blog/ejb is not found. Original exception : org.omg.CosNaming.NamingContextPackage.NotFound
[3/5/04 15:26:59:122 EST] 675fd904 DeployedAppli W WSVR0206E: Module, hibernate_ejb.jar, of application, ewwcms_hibernateEAR.ear/deployments/ewwcms_hibernateEAR, failed to start
[3/5/04 15:26:59:153 EST] 675fd904 ApplicationMg W WSVR0101W: An error occurred starting, ewwcms_hibernateEAR
[3/5/04 15:26:59:169 EST] 675fd904 ApplicationMg A WSVR0217I: Stopping application: ewwcms_hibernateEAR
[3/5/04 15:26:59:232 EST] 675fd904 WebContainer A SRVE0170I: Stopping Web Module: ewwcms.
[3/5/04 15:26:59:294 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: SimpleFileServlet: destroy
[3/5/04 15:26:59:294 EST] 675fd904 WebGroup I SRVE0180I: [ewwcms] [/ewwcms_hibernate] [Servlet.LOG]: JSP 1.2 Processor: destroy
[3/5/04 15:26:59:325 EST] 675fd904 ApplicationMg A WSVR0220I: Application stopped: ewwcms_hibernateEAR
[3/5/04 15:26:59:388 EST] 675fd904 HttpTransport A SRVE0171I: Transport http is listening on port 9,080.
[3/5/04 15:27:02:403 EST] 675fd904 HttpTransport A SRVE0171I: Transport https is listening on port 9,443.
[3/5/04 15:27:02:466 EST] 675fd904 RMIConnectorC A ADMC0026I: RMI Connector available at port 2809
[3/5/04 15:27:02:544 EST] 675fd904 WsServer A WSVR0001I: Server server1 open for e-business
[3/5/04 15:27:07:763 EST] 57d1913 WebContainer W SRVE0017W: Web Group not found: default_host/ewwcms_hibernate
[3/5/04 15:27:07:794 EST] 57d1913 OSEListenerDi E PLGN0021E: Servlet Request Processor Exception: Virtual Host/WebGroup Not Found : The web group default_host/ewwcms_hibernate has not been defined

Why is it that the "java.lang.NoClassDefFoundError: net/sf/hibernate/cfg/Configuration" is happening when I have setup all the configuration according to the above article.
Pleas help!


Top
 Profile  
 
 Post subject:
PostPosted: Mon Mar 08, 2004 12:42 pm 
Newbie

Joined: Tue Feb 03, 2004 11:58 am
Posts: 11
The problem is fixed.
Thanks to anybody who paid the attention to the question!


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