File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes EJB Certification (SCBCD/OCPJBCD) and the fly likes Calling a EJB from another EJB Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Calling a EJB from another EJB" Watch "Calling a EJB from another EJB" New topic

Calling a EJB from another EJB

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 389
I am trying to call a EJB from another EJB. I did this by JNDI lookup & then doing the usual stuff for calling the EJB. So Is there any better way of doing this. Because, wound'nt this be a overhead.. i mean maknig a lookup.

SCJP 1.4, SCWCD 1.4, SCBCD 1.5, TOGAF 9, Comptia Cloud+
Mansur Khan
Ranch Hand

Joined: Mar 27, 2007
Posts: 50
If both your EJB's are on the same application server, they can use EJBLocalObject and EJBLocalHome Interfaces to better the perfomance during look. Or may be a cached service locator can help. An approach like Spring can help better through DI (IOC). I will not want to talk on the Spring Approach as it would be out-of-scope.

Mahesh Desai
Ranch Hand

Joined: Apr 04, 2007
Posts: 76
Hi Shashank,

You could implement two J2EE design patterns in this case. [1] Session Facade & [2] Service Locator. You can maintain a Session Bean as Session Fa�ade on the EJB container. So the client side business delegator would always interact with this Session Facade by looking up for the Session Bean (Session Fa�ade) by using Service Locator. In this case, this call would be the remote call and for that you would be using EJBObject and EJBHome. This session facade would be the entry point to access other EJB's. Other EJB calls would be local calls for the session fa�ade and for that you would be using EJBLocalObject and EJBLocalHome and this practice would increase the performance of your app. This is applicable if all the EJB�s are deployed on same application server.


SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
I agree. Here's the link:
subject: Calling a EJB from another EJB
It's not a secret anymore!