I still don't understand why you need the POJO. Any way, how you can
look up an EJB from a POJO depends on where the POJO is used. If the
POJO is used from a web component like Servlet or JSP, then you need to
defined a ejb-ref or ejb-local-ref in web.xml; if it is used from an
EJB, then you need to define ejb-ref or ejb-local-ref in ejb-jar.xml; if
it is used in an appclient, then you need to define ejb-ref or
ejb-local-ref in application-client.xml. Take a look at chapter #5 of
the "Java EE 5 platform specification" for more details.
See my comments in line as well.
angelogeminiani wrote:
> My sample works fine if I declare @EJB in a test servlet, or web service.
> However, I'm not able to use JNDI lookup, nor injection, inside a simple
> class.
>
>
You can't use injection in a simple POJO. Injection is supported for
classes whose creation can be controlled by container, e.g., Servlet,
EJB, appclient, etc.
> public class SimplePOJO {
>
> private void lookup(){
> try {
> Context c = new InitialContext();
> name = NewsEntityFacade.class.getName().toString();
> obj = c.lookup( name );
>
This will not work. Your EJB has only a local business interface, so it
does not have a global JNDI name.
> name = "java:comp/env/NewsEntityFacade";
> obj = c.lookup( name );
>
>
This will work provided you write an appropriate XML descriptor which
contains the following:
<ejb-local-ref>
<ejb-ref-name>NewsEntityFacade</ejb-ref-name>
<ejb-ref-type>Session</ejb-ref-type>
<local>packagename.INewsEntityFacadeLocal</local>
<ejb-link>NewsEntityFacade</ejb-link>
</ejb-local-ref>
Thanks,
Sahoo