File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB and other Java EE Technologies and the fly likes EJB Handles Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "EJB Handles" Watch "EJB Handles" New topic

EJB Handles

Greg Charles

Joined: Oct 01, 2001
Posts: 2969

I've always read that when passing around an EJBObject, you should pass its handle, not the object itself. I've dutifully followed this rule in my own coding. Now I've come into a project where they retrieve an EntityBean through a finder method, then proceed to pass it around freely, even through session bean calls that return it to a different JVM. As far as I can tell though, everything works fine. So, what's the point of using handles?

Joined: Apr 23, 2002
Posts: 10
Hiding program setting,such as Provider url,host,...,etc.
Pradeep bhatt
Ranch Hand

Joined: Feb 27, 2002
Posts: 8927

Handles are serializable and consume less memory

Dave Landers
Ranch Hand

Joined: Jul 24, 2002
Posts: 401
If you are passing the ejb reference amongst "normal" java classes then this is probably OK.
The Handle is serializable and thus is good for stuffing in a cache or something like HttpSession. It is also useful to pass to remote objects ("over the wire" to another machine").
Dave Coombes

Joined: Nov 06, 2001
Posts: 19
For what it's worth, you can use HomeHandles in a modified version of the EJBHomeFactory pattern when you have (for instance) a web container and an EJB container in separate processes or on separate nodes which may be started and stopped separately as the HomeHandle is valid for separate runs of the EJB container whereas the EJBHome reference is not.
John King
Ranch Hand

Joined: Aug 27, 2002
Posts: 165
Originally posted by Pradeep Bhat:
Handles are serializable and consume less memory

Handle is an interface. How can you serialize
it? What really serialized is the EJBObject.
Chris Mathews
Ranch Hand

Joined: Jul 18, 2001
Posts: 2712
It makes no difference whether Handle is an interface, you are serializing the class that implements that interface not the interface itself. For the record EJBObject is an interface also.
Eduard Manas
Ranch Hand

Joined: May 12, 2002
Posts: 69
I'm slightly confused now,
EJBObject implements java.rmi.Remote, whereas Handle implements
Knowing that you can only pass either primitive values (ie int, float, double...) or serializable objects to remote objects (ie EJBs), would I be right to say that if you want to pass an EJB to another EJB (in another JVM), I cannot pass the EJBObject (it is not serializable) but I can pass the Handle?
If the above is right, how do you pass the remote interface to another EJB?
I agree. Here's the link:
subject: EJB Handles
It's not a secret anymore!