• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

bean reference

 
prat de
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how can a bean pass a reference of itself to some other bean?
- prat
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prat
A bean can get a handle to itself and pass that to another bean.
This does have dangers associated with it though, especially since this could make it possible for concurrent access to the bean (which is not allowed).
Regards, Andrew
 
prat de
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how the get a handle and pass to some other bean that's what i wanted to know, is it either by
passing a ‘this’ variable or passing a reference to the Home interface for the bean or passing a reference to the Remote interface for the bean
or by passing its Home Interface name.
how exactly I should do it.
- prat
 
Andrew Monkhouse
author and jackaroo
Marshal Commander
Pie
Posts: 12007
215
C++ Firefox Browser IntelliJ IDE Java Mac Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Prat,
Take a look at the methods of javax.ejb.SessionContext or javax.ejb.EntityContext. In both cases they have a getEJBObject() method that obtains a reference to the EJB Object currently associated with the instance.
From the API:
An instance can use this method, for example, when it wants to pass a reference to itself in a method argument or result.

The EJBObject has a getHandle() method which can be used to persist the reference to the EJBObject. Sorry for sending you on the wrong path before.
It is a bad idea to use the "this" variable within EJBs - the instance of the bean associated to your Entity or Session object could change.
Are you studying for the SCBCD exam? If so, how close are you to going for the exam?
Regards, Andrew
 
prat de
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
my interpretation:
these are the foll two ways a bean can pass a reference of itself to some other bean:
1. passing a "this" reference
2. passing the EJBObject reference obtained from Session/Entity Context.
It may be a bad idea to use the "this" variable within EJBs - the instance of the bean associated to Entity or Session object could change but this is one of the ways we can pass a reference whether it is practically not advisable is second issue...am i right...if incorrect please do correct me...
I am studying fro SCBCD and my target to complete the exam within another 5 weeks.
-prat.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic