• 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
  • Ron McLeod
  • Rob Spoor
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Henry Wong
  • Liutauras Vilda
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Tim Holloway
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Mikalai Zaikin
  • Piet Souris

How to pass reference of Entity Beans ?

 
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,
I have written a bean managed entity bean. I want to access it from a class and send the reference of that bean instance to another method, in another class. I really appreciate If somebody can tell me how to pass reference of a entity bean within methods . Thank you.
Regards,
Sanjaya.
 
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sanjaya, all EJB clients can only be accessed through their interfaces local or remote, for otherwise the EJB contract would be violated. So clients of EJB's have to get hold of that interface.
Since EJB2.0 allows you create an EJB reference by binding a home interface to a JNDI name in the application deployment descriptor, it seems to me you could use this mechanism to get access to your entity bean's home interface from different places avoiding passing it as a parameter in method invocations.
I assume that since you use the entity bean for its persistent data, that you can always access a consistent snapshot by using the appropriate transactional attributes in the bean's methods.

[This message has been edited by Jorge Phillips (edited October 24, 2001).]
 
author
Posts: 3892
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think Sanjaya's question was simpler than that. All you must do is once you have an instance of a bean, obtained through the standard way:
// Look up the home in JNDI
Object homeRef = initialContext.lookup("MyHome");
MyHome home = (MyHome) PortableRemoteObject.narrow(homeRef, MyHome.class);
// Now get the bean reference
Bean myBean = home.create(...parms here...);
You can then pass the "myBean" reference to other classes.
thing.doThisWith(myBean);
There is some sample code on doing this (and why) in my book, or in this article here: http://www7.software.ibm.com/vad.nsf/Data/Document4359?OpenDocument&p=1&BCT=1&Footer=1.
Kyle

------------------
Kyle Brown,
Author of Enterprise Java (tm) Programming with IBM Websphere
See my homepage at http://members.aol.com/kgb1001001 for other WebSphere information.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
are u a sri lankan ,if so I would like to meet u .I'm developing EJB programmes using BEA web logic server .
I have got some doubts hope u can help me.
 
reply
    Bookmark Topic Watch Topic
  • New Topic