File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes EJB and Other Java EE Technologies and the fly likes How to pass reference of Entity Beans ? Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » EJB and Other Java EE Technologies
Reply Bookmark "How to pass reference of Entity Beans ?" Watch "How to pass reference of Entity Beans ?" New topic
Author

How to pass reference of Entity Beans ?

Sanjaya KasthuriArachchi
Greenhorn

Joined: Feb 06, 2001
Posts: 5
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

Joined: Jun 03, 2001
Posts: 43
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

Joined: Aug 10, 2001
Posts: 3878
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.


Kyle Brown, Author of Persistence in the Enterprise and Enterprise Java Programming with IBM Websphere, 2nd Edition
See my homepage at http://www.kyle-brown.com/ for other WebSphere information.
rasika
Greenhorn

Joined: Jun 11, 2001
Posts: 8
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.
 
IntelliJ Java IDE
 
subject: How to pass reference of Entity Beans ?
 
Threads others viewed
purpose of ejbPostCreate method
ejbPostCreate()
bean reference
a bean pass a reference of itself to some other beans
ClassNotFoundException with Persistent Session
MyEclipse, The Clear Choice

cast iron skillet 49er

more from paul wheaton's glorious empire of web junk: cast iron skillet diatomaceous earth rocket mass heater sepp holzer raised garden beds raising chickens lawn care CFL flea control missoula heat permaculture