• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

bean reference

 
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
how can a bean pass a reference of itself to some other bean?
- prat
 
author and jackaroo
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Posts: 12200
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
And then the entire population worshiped me like unto a god. Well, me and this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic