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 call an EJB from another EJB(both are in different jar files) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "how to call an EJB from another EJB(both are in different jar files)" Watch "how to call an EJB from another EJB(both are in different jar files)" New topic
Author

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

Golla Vensiri
Greenhorn

Joined: Aug 05, 2004
Posts: 10
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
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
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.


Anthony W.<br />MCP, SCJP 1.4, SCJD, SCWCD 1.3, SCWCD 1.4, SCBCD
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
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.


Ever Existing, Ever Conscious, Ever-new Bliss
Anthony Watson
Ranch Hand

Joined: Sep 25, 2003
Posts: 327
You're misinformed, Sadanand Murthy. Entity beans have home business methods.
Prakash Dwivedi
Ranch Hand

Joined: Sep 28, 2002
Posts: 452
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


Prakash Dwivedi (SCJP2, SCWCD, SCBCD)
"Failure is not when you fall down, Its only when you don't get up again"
Pho Tek
Ranch Hand

Joined: Nov 05, 2000
Posts: 761

finders, creators, etc... are lifecycle methods. One could call them business methods - but it's not very accurate.


Regards,

Pho
Sadanand Murthy
Ranch Hand

Joined: Nov 26, 2003
Posts: 382
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.
rahul V kumar
Ranch Hand

Joined: May 20, 2003
Posts: 82
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to call an EJB from another EJB(both are in different jar files)