• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

how to call an EJB from another EJB(both are in different jar files)

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I ahev a situation in which i have to call an EJB from an another EJB in an application. Both the EJBs are in diffrent jar files.

Can anyone help me with a sample code

Thanks in Advance
 
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no difference between how a regular java class calls an ejb method and how one ejb calls a method on another ejb. In all cases where ejb methods are called, you do the jndi lookup for the ejb home and then call business methods on the home or get a reference to an EJBObject from the home and call methods on it.
 
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Watson:
There is no difference between how a regular java class calls an ejb method and how one ejb calls a method on another ejb. In all cases where ejb methods are called, you do the jndi lookup for the ejb home and then call business methods on the home or get a reference to an EJBObject from the home and call methods on it.



EJB's home interface does not define any business methods. The home interface defines the ejb creation & life-cycles methods. The ejb's remote/local interface is where the business methods are defined. If you want to call a business method of the ejb, you have to get reference to the remote/local interface of the ejb.

To the OP:
You may also want to consider doing PortableRemoteObject.narrow() on the home interface returned by the jndi lookup.
 
Anthony Watson
Ranch Hand
Posts: 327
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You're misinformed, Sadanand Murthy. Entity beans have home business methods.
 
Ranch Hand
Posts: 452
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Entity beans have home business methods



If business method's are written in home interface, than what will you write in remote / local interface? I believe home interface is use to write EJB life cycle method (create, find, destroy, select etc.)

I'll even say why to have business method in Entity Bean first of all. Won't it be better to have business methods defined in Session Bean?

regards
 
Ranch Hand
Posts: 782
Python Chrome Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
finders, creators, etc... are lifecycle methods. One could call them business methods - but it's not very accurate.
 
Sadanand Murthy
Ranch Hand
Posts: 382
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Anthony Watson:
You're misinformed, Sadanand Murthy. Entity beans have home business methods.



The api documentaion for EJBHome does say this:


An enterprise Bean's remote home interface defines the methods that allow a remote client to create, find, and remove EJB objects, as well as home business methods that are not specific to a bean instance


So, you are correct Anthony, I was misinformed. Can you give me an instance of a business method in a home interface that you have created/used? I've never had to do this (I haven't written many entity ejbs). And I can't think of any scenario where I'd need to.
 
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
For example you could have a method
Collection getCustomersForCity(String city) in your Home Interface.

You need not get handle on EJBObject to get this information. Once you lookup your home you can call the above Home Business methods.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic