IntelliJ Java IDE
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes bean reference Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Professional Certification » EJB Certification (SCBCD/OCPJBCD)
Reply Bookmark "bean reference" Watch "bean reference" New topic
Author

bean reference

prat de
Greenhorn

Joined: Sep 15, 2003
Posts: 22
how can a bean pass a reference of itself to some other bean?
- prat
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 9982

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


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
prat de
Greenhorn

Joined: Sep 15, 2003
Posts: 22
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

Joined: Mar 28, 2003
Posts: 9982

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

Joined: Sep 15, 2003
Posts: 22
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.
 
 
subject: bean reference
 
Threads others viewed
Servlet JNDI Lookup SessionBean NameNotFound Exception
Problem Accessing Local EJB!!!!!!
ServiceLocator
Stateful session bean reference to entity beans passivate?
Passing this reference to another bean
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com