users@glassfish.java.net

Re: Accessing EJBs from a POJO

From: Ryan de Laplante <ryan_at_ijws.com>
Date: Thu, 29 Jan 2009 21:03:13 -0500

I don't think the @EJB annotation works in POJOs. It only works in
other EJBs, servlets, and JSF managed beans. It looks like what you are
trying to create is a "Service Locator", and loading the EJB from JNDI
is the right way to do it. I remember having difficulties doing this
with local EJB 3.0 session beans, because all of the examples on the web
are for remote EJB 3.0 session beans. Someone else will have to help
you with the exact syntax.

@PostLoad is from JPA and doesn't belong here.


Ryan



glassfish_at_javadesktop.org wrote:
> Hi,
>
> I followed the instructions on this page https://glassfish.dev.java.net/javaee5/ejb/EJB_FAQ.html#POJOLocalEJB but have so far been unsuccessful in getting a true POJO to be able to lookup an ejb through the jndi. I've tried the @EJB annotation as well as the <ejb-local-ref> in the web.xml file and it's a no go either way. Can anyone tell me if there is something I'm missing?
>
> Thanks,
>
> Drew
>
>
> @EJB(name="test",beanInterface=FormularyManagerLocal.class)
> public class EntityListener
> {
>
> @PostLoad
> public void postLoad(FormularyUser user)
> {
> InitialContext ctx;
> try
> {
> ctx = new InitialContext();
> Object obj = ctx.lookup("java:comp/env/test"); //$NON-NLS-1$
> assert obj != null;
> }
> catch (NamingException e1)
> {
> // TODO Auto-generated catch block
> e1.printStackTrace();
> }
> }
> }
> [Message sent by forum member 'utdrew' (utdrew)]
>
> http://forums.java.net/jive/thread.jspa?messageID=329101
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>
>