users@glassfish.java.net

Re: CDI injection broken between POJOs

From: Steven Siebert <smsiebe_at_gmail.com>
Date: Fri, 9 Apr 2010 19:36:36 -0400

Your POJO isn't container managed, so you can't use CDI like you can in an
EJB. The EJB container is what does the CDI magic for your EJBs.

If both your Entity and DAO are POJO's, why not simply instantiate the
SiteDAO using a constructor or a factory? If you're looking for the CDI to
do pooling or something like that, perhaps create a SLSB factory that can
retrieve it via CDI and return it to your POJO? You'll need to use JNDI to
retrieve a copy of your SLSB from the context.

Cheers,

Steve


On Fri, Apr 9, 2010 at 6:22 PM, <glassfish_at_javadesktop.org> wrote:

> I have a POJO User entity that needs to get a POJO SiteDao injected into
> it, but GF or Weld seems to be ignoring my @Inject annotation.
>
> @Inject does work in my EJB, but not in my POJO User entity. Both are in
> the same EJB module, which has the empty beans.xml.
>
> When I invoke my EJB, I can see that the SiteDao that should've been
> injected is null:
>
> Caused by: java.lang.NullPointerException
> at sample.model.User.getSite(User.java:15)
> at sample.service.UserService.getSiteByUserGuid(UserService.java:26)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.glassfish.ejb.security.application.EJBSecurityManager.runMethod(EJBSecurityManager.java:1055)
> at
> org.glassfish.ejb.security.application.EJBSecurityManager.invoke(EJBSecurityManager.java:1127)
> at
> com.sun.ejb.containers.BaseContainer.invokeBeanMethod(BaseContainer.java:5259)
> at
> com.sun.ejb.EjbInvocation.invokeBeanMethod(EjbInvocation.java:615)
> at
> com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
> at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
> at
> org.jboss.weld.ejb.SessionBeanInterceptor.aroundInvoke(SessionBeanInterceptor.java:57)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
> at
> com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
> at com.sun.ejb.EjbInvocation.proceed(EjbInvocation.java:567)
> at
> com.sun.ejb.containers.interceptors.SystemInterceptorProxy.doAround(SystemInterceptorProxy.java:158)
> at
> com.sun.ejb.containers.interceptors.SystemInterceptorProxy.aroundInvoke(SystemInterceptorProxy.java:140)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> com.sun.ejb.containers.interceptors.AroundInvokeInterceptor.intercept(InterceptorManager.java:858)
> at
> com.sun.ejb.containers.interceptors.AroundInvokeChainImpl.invokeNext(InterceptorManager.java:797)
> at
> com.sun.ejb.containers.interceptors.InterceptorManager.intercept(InterceptorManager.java:367)
> at
> com.sun.ejb.containers.BaseContainer.__intercept(BaseContainer.java:5231)
> at
> com.sun.ejb.containers.BaseContainer.intercept(BaseContainer.java:5219)
> at
> com.sun.ejb.containers.WebServiceInvocationHandler.invoke(WebServiceInvocationHandler.java:189)
> ... 66 more
>
> My simple EAR is attached.
>
> Anyone know a workaround?
>
> Thanks,
> -Dan
> [Message sent by forum member 'theodan']
>
> http://forums.java.net/jive/thread.jspa?messageID=396170
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>