3
votes

I want to store a reference to a Stateful Session Bean and save it to the database or transfer it to another VM. As far as I read, in EJB 2.x this is possible using getHandle(). If I try to serialize the SFSB instance using Glassfish 3.1.1, I get the following exception:

java.io.NotSerializableException: com.sun.ejb.containers.EJBLocalObjectInvocationHandlerDelegate

Furthermore, I haven't found a way to obtain a SFSB handle. All references in the SFSB SessionContext to EFBHome, EFBObject, EFBLocalHome are null, even if the bean is properly being managed by the container. If I understand the spec correctly, there shouldn't be a need for handles in EJB 3.1 anyway, because developers should be able to use the SFSB reference directly.

This article deals with the same issue, but the suggested use of the JavaEEObjectInputStream class did not expose the method readObject in my tests. I wonder how this approach could ever work.

Can anyone suggest a good approach to serialize a SFSB in Glassfish to store the reference? I don't want to attach the reference to a HTTPSession (I am just saying this, because people recommend this everywhere).

1
Maybe it is not a satisfying answer, but why not use the old raw EJB 2 code with jndi lookup and portable narrow object ? It still works even for EJB declared with 3.x annotations... - Yves Martin

1 Answers