Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

How to pass reference of Entity Beans ?  RSS feed

 
Sanjaya KasthuriArachchi
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • 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.
 
Jorge Phillips
Ranch Hand
Posts: 43
  • Mark post as helpful
  • send pies
  • 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).]
 
Kyle Brown
author
Ranch Hand
Posts: 3892
5
  • Mark post as helpful
  • send pies
  • 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.
 
rasika
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!