Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

javax.ejb.Handle

 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone,

After some reading, I still cannot understand why we need the javax.ejb.Handle ? What is wrong with keeping a reference to an EJB object?

What am I missing here?
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not an expert in the field, but I think that when you are using remote beans, the reference the client owns is not the same as what the server owns.
A Handle uniquely identifies a bean in the server. You could save a Handle, reuse it later, and you'll get the same bean (as long as it's still alive).
 
Sunil Dixit
Ranch Hand
Posts: 46
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
'Satou ' is right, actually EJBHandle is Serializable object which can be presisted and can be used in future to call ejb methods.
It is use to avoid re lookup/re creation of EJObject.
Only problem with EJBHandle is maintaing the reference to non-existing proxy on the server (i.e. associated ejb bean instance is no longer there) than it will throw runtime exception.
Hope that this will make clear picture to you.

Cheers,
Sunil Dixit
 
Joseph Sweet
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got it now. I was reading "Mastering EJB" and the code example there looked as if the remote client gets the stub (of an EJB object), then it gets the handle from the stub, then they said that the client "waits some time", then it uses the handle to get a stub again.

The misleading thing in that description was that the client looks as if he does all those actions in one long process. Which is not. Had he done, there was no use to get a handle... he could have just keep using the stub, which is what my original question was asking.

What that they actually meant is that "wait some time" means: the client ends the process, emails himself the stub, turn off the computer at home, go to bed, wake up in the morning, go to work, gets the stub from his email, and gets a (new) stub to his good old bean from last night.

But why bothering to write it? Why not misleading the readers and let them sweat?

As for what Sunil Dixit wrote:

It is use to avoid re lookup/re creation of EJObject.


Not as far as I know. What that the handle gives that guy from his work computer he cannot get with any lookup if the bean is stateful session bean. His only hope to get exactly his bean from last night (or more precisely, some bean with last night's state), is to use the handle.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic