Is it legal to pass a reference to a Session Bean in a remote call to a method that starts a new transaction? I have one Session Bean A that calls one of its own methods remotely in a loop (where the invoked method has a transaction attribute of "requires new"). The called method makes a remote call to Session Bean B. Rather than looking up Session Bean B each time through the loop, I would like to look up Session Bean B once and then pass its reference to the remote method of Session Bean A. The thing is, I'm not sure if it is legal to pass a reference to a Session Bean in a remote call, especially since the remote method has a different transaction attribute. This would definitely be a problem with an Entity Bean, but is it a problem with a Session Bean? On a related topic, what if, instead of passing a reference to a Session Bean to a remote method that starts a new transaction, I wanted to pass a reference to an Entity Bean's Home Interface? Would that be legal? Thanks.
Yes, you can pass a HomeHandle reference to the method. Once you have the reference to the session bean's Home object, you can create a handle to the home object by calling getHomeHandle(). getHomeHandle() returns a HomeHandle object, that can be used to obtain the home interface to the same EJB at a later time. A client can pass the HomeHandle object as arguments to another client, and the receiving client can use the handle to obtain a reference to the same EJBHome object. HomeHandle implements Serializable and hence one can also serialize the HomeHandle and store it in a file for later use. Beware that HomeHandle implementation, like a lot of other things, is dependent on the vendor. Vendor specific implementation might store "extra" information in the handle that may become stale( such as IP addresses and host information) if you try to keep the handle around for a very long time in a serialized form.
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).