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?
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").
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.
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