aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes javax.ejb.Handle Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "javax.ejb.Handle" Watch "javax.ejb.Handle" New topic
Author

javax.ejb.Handle

Joseph Sweet
Ranch Hand

Joined: Jan 29, 2005
Posts: 327
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?


We must know, we will know. -- David Hilbert
Christophe Verré
Sheriff

Joined: Nov 24, 2005
Posts: 14688
    
  16

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


[My Blog]
All roads lead to JavaRanch
Sunil Dixit
Ranch Hand

Joined: Sep 22, 2005
Posts: 46
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

Joined: Jan 29, 2005
Posts: 327
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: javax.ejb.Handle