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.
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).]
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