We do the following within a Session Bean:
[code]
@EJB(name = "ejb/ExampleSessionBean", beanName = "ExampleSessionBean")
ExampleSessionLocal bean;
[/code]
and then:
[code]
ExampleSessionLocal bean;
Context c = new InitialContext();
bean = (ExampleSessionLocal) c.lookup("java:comp/env/ejb/ExampleSessionBean");
[/code]
The key if you go down this path is that if you have POJO that needs to look up a local reference, AND that POJO is called from another Session Bean, then THAT session bean need to have this declaration in it, even if it's not used directly by the session bean.
I don't know if there is a way to globally set that kind of mapping up or not, but the crux of the problem is that local reference are NOT bound in to the global JNDI tree (since, well, it's global!). But each Session Bean has ITS OWN local JNDI space, and these declarations within the Session Bean map those resources in to the local tree.
When the POJO is called, it's looking at the local JNDI tree, and each Session Bean has their own version of the local tree. So each Session Bean that calls that POJO needs to have the mapping added to it.
At least, that's my best understanding of it -- perhaps someone can clarify it (though this
https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html talks about it best). The whole JNDI and resource mapping aspect of EJB has always alluded me. I never quite understood that whole mechanism and have simply bumbled through life with cookbook examples without actually understanding how they work.
[Message sent by forum member 'whartung' (whartung)]
http://forums.java.net/jive/thread.jspa?messageID=241971