Help coderanch get a
new server
by contributing to the fundraiser
  • 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
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

Session Beans method to be called from session bean

 
Ranch Hand
Posts: 413
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Get a reference to the session beans home object and then run the create method.
 
Ranch Hand
Posts: 1143
1
Eclipse IDE Oracle Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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,

Avi.

------------------
 
Ranch Hand
Posts: 118
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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) {
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic