Dan,
You have an interesting use case. IIUC from your sample, you are trying
to do the following:
1. UserService SLSB is injected with UserDao. It calls UserDao to return
a User. See step #2.
2. UserDaoImpl calls entitymanager.find to return a User.
3. User is injected with SiteDao.
The user returned in step #2 does not get injected with SiteDao,
correct? This is going to be tricky. User object returned in step #2
does not go through CDI at all. It's not as if you injected a User
instance into another bean. So, why do you expect SiteDao to be injected
into the User instance, which is returned by entity manager. I don't
know CDI that well. Is Decorators applicable here? Could you decorate
User bean and add inject SiteDao in your decorator bean?
Thanks,
Sahoo
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
>
>