• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

bean reference

 
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
 
author and jackaroo
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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
Posts: 12199
280
Mac IntelliJ IDE Firefox Browser Oracle C++ Java
  • 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.
 
Water! People swim in water! Even tiny ads swim in water:
the value of filler advertising in 2020
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic