wood burning stoves 2.0*
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


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » EJB Certification (SCBCD/OCPJBCD)
Bookmark "Calling a EJB from another EJB" Watch "Calling a EJB from another EJB" New topic
Author

Calling a EJB from another EJB

Nikhil Jain
Ranch Hand

Joined: May 15, 2005
Posts: 385
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
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.


SCDJWS, SCBCD, SCJP
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.

Thanks,
Mahesh

-------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (SCEA Part I preparing......)
 
 
subject: Calling a EJB from another EJB