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

Can a Local EJB call another Local EJB?

Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
More fun with local homes:
Hi all-
Q. Can a local EJB look up another local EJB in the same EJB project?
I'm trying to do this but am getting an error:
I have a CMP bean (userPoolEntity localHome) and a Stateless Session Bean (userPoolManager, also LocalHome) in the same EJB project:
I can look up the CMP from the JNDI test client fine as well as the Session bean. But when I get to a method in the Session bean where it tries to look up the Entity bean, I get a naming error:
javax.naming.NameNotFoundException: Name comp/env/ejb/userpool not found in context "java:".
I also get a Console error starting EJB:
Starting EJB jar: UserPoolEJB.jar
Unable to start EJB jar, UserPoolEntity: Name "userPoolEntity" is already bound to the context "local:ejb/ejb/userpool".
Unable to start EJB jar, UserPoolManager: Name "userPoolManager" is already bound to the context "local:ejb/ejb/userpool".
Here's the lookup code in my session bean (local):
String ENTITYLOCALHOME="java:comp/env/ejb/userpool/userPoolEntity";
try {
InitialContext ctxt = new InitialContext();
UserPoolEntityLocalHome home =
(UserPoolEntityLocalHome) ctxt.lookup(ENTITYLOCALHOME);
return home;
} catch (NamingException ne) {
return null;
Here's the EJB bind file ( I stripped out the < and > chars because I know it's hard to paste XML here):
?xml version="1.0" encoding="UTF-8"?
ejbbnd:EJBJarBinding xmi:version="2.0" xmlns:xmi=""
xmlns:ejbbnd="ejbbnd.xmi" xmlns:ejb="ejb.xmi" xmlns:commonbnd="commonbnd.xmi" xmlns:common="common.xmi" xmi:id="EJBJarBinding_1067823339758" currentBackendId="DB2UDBNT_V72_1"
ejbJar href="META-INF/ejb-jar.xml#ejb-jar_ID"/
ejbBindings xmi:id="EnterpriseBeanBinding_1067823339758" jndiName="ejb/userpool/userPoolEntity"
enterpriseBean xmi:type="ejb:ContainerManagedEntity" href="META-INF/ejb-jar.xml#UserPoolEntity"/
ejbBindings xmi:id="EnterpriseBeanBinding_1068043090513" jndiName="ejb/userpool/userPoolManager"
enterpriseBean xmi:type="ejb:Session" href="META-INF/ejb-jar.xml#UserPoolManager"/
ejbRefBindings xmi:id="EjbRefBinding_1068077814639" jndiName="ejb/userpool/userPoolEntity"
bindingEjbRef xmi:type="common:EJBLocalRef" href="META-INF/ejb-jar.xml#EJBLocalRef_1068077814649"/
defaultCMPConnectionFactory xmi:id="CMPConnectionFactoryBinding_1067824135703" jndiName="jdbc/b1"/

Seems like a circular ref. of some sort:
Should I split into two EJB projects?
BTW, if I go to my EJB project to generate RMIC code, it always shows the beans as needing to be generated, even if I just did so.
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Of course, Yes.
but I am surprised to see that you made your session bean local. Could you please tell me what made you to make ur session bean local?
Circular references happens only if Project A depends on Project B and Project B depends on Project A. Same with Classes. In ur case I couldnt find anything like that unless you had something else other than you mentioned in the code.
Here is what you need to do step by step to get your Ejb references work fine.
1. Ejb1 refer to Ejb2.
From the EJB Deployment descriptor create the Ejb reference. Note the name you give to this reference and thats the name you will use in ur code with java:comp/env/referenceName
2. Web project to ejb project
Other than what you did above, you have to do the same with Web deployment descriptor to make this reference to ejbs. (You will select Ejb if it is remote and ejblocal if it is local)
Here also, the name you are giving for the reference will be the name you use with java:/comp/env
Now, let me know if you are still facing problem...
Have fun
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Mahesh-
Thanks for the reply.
I'm making the session bean local at this point for performance reasons. This is a proof of concept project and all I want is to leverage the transactional capabilites at this point.
As far as references go, I thought I set it up right. I'm not doing any web references at this point (just trying to use the JNDI test client) so I can't figure out why I can't reference the CMP from within the session bean.
Any ideas?
Max Tomlinson
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
stupidity strikes again:
I should have used:

thank you for listening

I want my playground back. Here, I'll give you this tiny ad for it:
We need your help - Coderanch server fundraiser
    Bookmark Topic Watch Topic
  • New Topic