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
Hiding program setting,such as Provider url,host,...,etc.
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").
Joined: Nov 06, 2001
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.
Joined: Aug 27, 2002
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.
Joined: Jul 18, 2001
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.
Joined: May 12, 2002
Guys, I'm slightly confused now, EJBObject implements java.rmi.Remote, whereas Handle implements java.io.Serializable. 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? Eduard