• 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 ...
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Session Beans method to be called from session bean

Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As we all know that for calling a method of a different bean
from one bean we have to first get the ejbobject and then call the method
for calling a entity bean from session bean
we first of all create primary key object using primarky key class and then use findByprimaryKey to get the ejb object
and subsequently call the method of entity bean
can anyone tell me how to do the same procedure if we have to call session bean's method from our current session bean?
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Get a reference to the session beans home object and then run the create method.
Ranch Hand
Posts: 1143
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Gaurav,

I agree with Thomas. The only way I know of to invoke a method on
a bean (any type, from anywhere) is to first get a reference to
the bean's remote interface, and the only way to do that for a
session bean (that I know of), is to lookup the bean's home
interface and then invoke the "create" method. For an entity bean
-- as you say -- you can use "findByPrimaryKey".

Of-course, that's why (IMO) the EJB 2 spec introduces the local
home interface and local remote interface -- so that a session
bean can more easily and more quickly get a reference to another
bean's remote interface.

Good Luck,


Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Obtain the Initail context and then look up for the Home nad one you obtained the home object then call its create method to ogtain the remote object
try the following code and make it suit to your case

private static EJBRemote getRemote() throws RemoteException
try {
javax.naming.Context context getInitialContext();
EJBHome home = (EJBHome)context.lookup("lookupname");
return home.create();
} catch (Exception e) {
Consider Paul's rocket mass heater.
    Bookmark Topic Watch Topic
  • New Topic