Skip to Main Content

Java EE (Java Enterprise Edition) General Discussion

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem in HelloWorld example in EJB

843829Mar 22 2002 — edited Sep 11 2003
Hi, I am learning EJB right now. I used weblogic before. I followed HelloWorld example in chapter three in book "Master Enterprise JavaBean II" and tried to make it work on Weblogic 6.1. But I have some problems as I described as below:

The OS: Window 2000 Server with sp2
Application Server: BEA weblogic 6.1
JDK 1.3.1

The code is the same as in the book:

// Hello.java
package examples;

import java.rmi.RemoteException;
import javax.ejb.EJBObject;
import javax.ejb.EJBHome;
import javax.ejb.Handle;

public interface Hello extends EJBObject {
public String hello() throws RemoteException;
}

// HelloHome.java
package examples;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface HelloHome extends EJBHome {
Hello create() throws RemoteException, CreateException;
}

// HelloLocal.java
package examples;

import javax.ejb.EJBLocalObject;
import javax.ejb.EJBLocalHome;

public interface HelloLocal extends EJBLocalObject {
public String hello();
}

// HelloLocalHome.java
package examples;

import javax.ejb.CreateException;
import javax.ejb.EJBLocalHome;

public interface HelloLocalHome extends EJBLocalHome {
HelloLocal create() throws CreateException;
}

// HelloBean.java
package examples;

import javax.ejb.SessionBean;
import javax.ejb.SessionContext;

public class HelloBean implements SessionBean {
private SessionContext ctx;

public void ejbCreate() {
System.out.println("ejbCreate()");
}

public void ejbRemove() {
System.out.println("ejbRemove()");
}

public void ejbActivate() {
System.out.println("ejbActivate()");
}

public void ejbPassivate() {
System.out.println("ejbPassivate()");
}

public void setSessionContext(SessionContext ctx) {
this.ctx = ctx;
}

public String hello() {
System.out.println("hello()");
return "Hello World!";
}
}

// ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" "http://java.sun.com/dtd/ejb-jar_2_0.dtd">
<ejb-jar>
<enterprise-beans>
<session>
<ejb-name>Hello</ejb-name>
<home>examples.HelloHome</home>
<remote>examples.Hello</remote>
<local-home>examples.HelloLocalHome</local-home>
<local>examples.HelloLocal</local>
<ejb-class>examples.HelloBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
</session>
</enterprise-beans>
</ejb-jar>

//weblogic-ejb-jar.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- edited with XML Spy v4.2 U (http://www.xmlspy.com) by name (china) -->
<!DOCTYPE weblogic-ejb-jar PUBLIC "-//BEA Systems, Inc.//DTD WebLogic 6.0.0 EJB//EN" "http://www.bea.com/servers/wls600/dtd/weblogic-ejb-jar.dtd">
<weblogic-ejb-jar>
<weblogic-enterprise-bean>
<ejb-name>Hello</ejb-name>
<jndi-name>HelloHome</jndi-name>
<local-jndi-name>HelloHome</local-jndi-name>
</weblogic-enterprise-bean>
</weblogic-ejb-jar>

I can deploy the jar file into weblgoic successfully. I didn't see any error message in the weblogic console, so I assume that everything is fine. Now I create HelloClient.java file:

// HelloClient.java
package examples;

import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;

public class HelloClient {
public static void main(String[] args) throws Exception {
Properties props = System.getProperties();
props.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory");
props.put(Context.PROVIDER_URL, "t3://localhost:7001");

Context ctx = new InitialContext(props);

Object obj = ctx.lookup("HelloHome");

HelloHome home = (HelloHome)javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class);

Hello hello = home.create();

System.out.println(hello.hello());

hello.remove();
}
}

The only thing I changed from the book for this file is that I add the JNDI look up properties as weblogic's requirement. I compiled this file, and try to run it, I got the following errors:

Exception in thread "main" javax.naming.ConfigurationException. Root exception
is java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl

Start server side stack trace:
java.rmi.MarshalException: error marshalling return; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace
; nested exception is:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHo
meImpl

Start server side stack trace:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace

java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl

Start server side stack trace:
java.io.NotSerializableException: examples.HelloBean_15fz5e_LocalHomeImpl
at java.io.ObjectOutputStream.outputObject(ObjectOutputStream.java:1148)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:366)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:102)
at weblogic.common.internal.ChunkedObjectOutputStream.writeObject(Chunke
dObjectOutputStream.java:108)
at weblogic.jndi.internal.RootNamingNode_WLSkel.invoke(Unknown Source)
at weblogic.rmi.internal.BasicServerRef.invoke(BasicServerRef.java:296)
at weblogic.rmi.cluster.ReplicaAwareServerRef.invoke(ReplicaAwareServerR
ef.java:93)
at weblogic.rmi.internal.BasicServerRef.handleRequest(BasicServerRef.jav
a:265)
at weblogic.rmi.internal.BasicExecuteRequest.execute(BasicExecuteRequest
.java:22)
at weblogic.kernel.ExecuteThread.execute(ExecuteThread.java:139)
at weblogic.kernel.ExecuteThread.run(ExecuteThread.java:120)
End server side stack trace

<

It looks like that it complains that HelloBean is not serializable, but it implements SessionBean interface which finaly extends from serializable. I don't know why this error happened? Is anything wrong with the code? Or some configuration is not right? I am very new to EJB and now I hang up on this error. Any one knew the reason?

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 9 2003
Added on Mar 22 2002
5 comments
323 views