Passing References from One Entity Bean to Another

There are cases when an entity bean needs to pass a reference to itself to another entity bean. In a non-EJB program, you occasionally need to pass this as a parameter to a method. In the EJB world, however, a remote method usually expects a Remote interface as a para meter, and the this reference for an implementation class is not a proper remote reference, even if the implementation class implements the Remote interface.

When you need to pass the equivalent of this—that is, when you need a remote reference to the current bean, whether it be a session bean or an entity bean—use the getEJBObject method in the EntityContext (or SessionContext) object. Don't forget to use the PortableRemoteObject.narrow ...

Get Special Edition Using Java™ 2 Enterprise Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.