Win a copy of Classic Computer Science Problems in Swift this week in the iOS forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

EJB Handles  RSS feed

 
Sheriff
Posts: 3015
12
Firefox Browser IntelliJ IDE Java Mac Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiding program setting,such as Provider url,host,...,etc.
 
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Handles are serializable and consume less memory
 
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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").
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 165
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Ranch Hand
Posts: 2713
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 69
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!