users@glassfish.java.net

Re: SessionBean Lookup/Injection from a pojo within the same EAR

From: <glassfish_at_javadesktop.org>
Date: Wed, 17 Sep 2008 07:18:15 PDT

Your POJO class will only see the environment from the EJB that it is being invoked within. If that EJB does not specify a dependency on the session bean either through annotation or through the ejb.xml deployment descriptor, then your POJO will never see the JNDI entry for the session bean.

So if in your application you have your MessageManagerBean which is annotated with its name and you have an EJB say called "SomeEJB" that is in turn invoking your POJO somewhere down the line, your POJO will only have the environment that is specified for "SomeEJB" and nothing else. To make this work you will need to either add an annotation to "SomeEJB" to declare its dependency on "MessageManagerBean"

[i]@EJB(name="ejb/MessageManagerBean", beanInterface=MessageManagerLocal.class)
public class SomeEJB implements SomeEJBLocal {
...
}[/i]

or specify this dependency in "ejb.xml":

[i]<session>
    <ejb-name>SomeEJB</ejb-name>
            <ejb-local-ref>
                <ejb-ref-name>ejb/MessageManagerBean</ejb-ref-name>
                <ejb-ref-type>Session</ejb-ref-type>
<local>MessageManagerLocal</local>
                <ejb-link>MessageMangerBean</ejb-link>
            </ejb-local-ref>
</session>
[/i]
[Message sent by forum member 'bbergquist' (bbergquist)]

http://forums.java.net/jive/thread.jspa?messageID=299834