This week's book giveaway is in the JavaScript forum.
We're giving away four copies of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js and have Paul Jensen on-line!
See this thread for details.
Win a copy of Cross-Platform Desktop Applications: Using Node, Electron, and NW.js this week in the JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing Session Bean References in Remote Calls  RSS feed

 
Brendan Conner
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually you can pass the reference too. It's perfectly legal. After all, that's how you GOT the reference in the first place, isn't it?
Kyle
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!