This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
From my app I can get a reference to one using something like -
home = (EJBLocalHome) context.lookup("java:comp/env/ejb/ejb1");
but trying to get a reference to another one from a method within ejb1 I have to use -
home = (EJBLocalHome) context.lookup("ejb/ejb2");
without the "java:comp/env/" bit otherwise I get a NamingException thrown
This must be happening because all different types of beans are maintained in separate container like Entity beans in different and Session Beans in different and so on. Specifying java:comp/env/ejb means specifying the environment for the component, where it should be looked for, i.e. in ejb. But this environment is already set in case when you try to access a EJB from another EJB, you don't need to specify java:comp/env/ejb again but only the lookup name as mentioned in xml file. As for accessing EJB from Session Bean or from Struts, you have to specify the component environment where to look for the ejb bean, along with its name mentioned in xml file because now you are accessing an entity Bean which lies in another container and not within same container where session Beans are.