cancel
Showing results for 
Search instead for 
Did you mean: 

java.io.NotSerializableException exception in session beans

Former Member
0 Kudos

Hey experts,

I have written the following code to call a session bean method from a portal application.

			Object obj1 = context.lookup("applications/knet");
			UserInfoHome userInfoHome =
							(UserInfoHome) javax.rmi.PortableRemoteObject.narrow(
							obj1,
							UserInfoHome.class);
			UserInfo userInfo = userInfoHome.create();
			Collection col =
						userInfo.getAllrooms();
			out.println("The size is  " + col.size() + "<br>");

The following is the implementation of the getAllrooms() method in the session bean

	public Collection getAllrooms() {
		Collection col = null;
		try {
			InitialContext ctx = new InitialContext();
			roomsHome = (RoomsLocalHome) ctx.lookup("java:comp/env/ejb/RoomsBean");
			col = roomsHome.findAllRooms();
		} catch (NamingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (FinderException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return col;
	}

In the entity bean the following EJB QL has been used

<EJB QL>

select object(r) from Rooms r

</<EJB QL>>

I get the following error

com.sap.engine.services.rmi_p4.exception.P4BaseRuntimeException: I/O operation failed : java.io.NotSerializableException: com.sap.engine.services.ejb.entity.finder.EJBLocalCollection :

at com.sap.engine.services.rmi_p4.server.P4ObjectBrokerServerImpl.getException(P4ObjectBrokerServerImpl.java:926)

at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.replicateReturnValue(LocalInvocationHandler.java:115)

at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.invokeInternal(LocalInvocationHandler.java:90)

at com.sap.engine.services.rmi_p4.reflect.AbstractInvocationHandler.invoke(AbstractInvocationHandler.java:50)

at $Proxy180.getAllrooms(Unknown Source)

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

at java.lang.reflect.Method.invoke(Method.java:324)

at com.sap.engine.services.ejb.session.stateless_sp5.ObjectStubProxyImpl.invoke(ObjectStubProxyImpl.java:187)

at $Proxy181.getAllrooms(Unknown Source)

at com.watercorp.BMS.test.EJBTest.doContent(EJBTest.java:120)

at com.sapportals.portal.prt.component.AbstractPortalComponent.serviceDeprecated(AbstractPortalComponent.java:209)

at com.sapportals.portal.prt.component.AbstractPortalComponent.service(AbstractPortalComponent.java:114)

at com.sapportals.portal.prt.core.PortalRequestManager.callPortalComponent(PortalRequestManager.java:328)

... 29 more

Caused by: java.io.NotSerializableException: com.sap.engine.services.ejb.entity.finder.EJBLocalCollection

at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1054)

at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:278)

at com.sap.engine.services.rmi_p4.reflect.LocalInvocationHandler.replicateReturnValue(LocalInvocationHandler.java:110)

... 42 more

Please help

Accepted Solutions (0)

Answers (2)

Answers (2)

Vlado
Advisor
Advisor
0 Kudos

Hi Sabbir,

You are trying to expose a Collection of Entity local interfaces (RoomsLocal) that is the result of RoomsLocalHome.findAllRooms(), through the Session bean's remote interface method getAllrooms(). This is forbidden by the EJB specification and of course cannot work. You have to use remote interfaces of Entity beans when you want to expose them to remote clients - although this is not a good practice either since Entity beans are fine-grained components. Data transfer objects (<a href="http://en.wikipedia.org/wiki/Data_Transfer_Object">DTO</a>) with Session facades should be used for this purpose (you already have a Session facade - the UserInfo bean).

Hope this clarifies it!

-Vladimir

Message was edited by:

Vladimir Pavlov

Former Member
0 Kudos

dont you think this explains it all

>>> java.io.NotSerializableException

have you checked your class hirearchy which you are passing in / out i.e. as parameters and as return types etc and check if all the classses (esp custom defined classes) are serializable.

Former Member
0 Kudos

Dear amal,

Only custom defined class I have is the AbstractPortalComponent which is as follows

public class EJBTest extends AbstractPortalComponent implements Serializable(){

doContent() {

// code in here

}

}

Do I need to make the Seession bean Serializable that actaually handles the entity beans.

Thnak you.