users@glassfish.java.net

Re: CDI broken between EJB and JPA modules

From: Arun Gupta <Arun.Gupta_at_Sun.COM>
Date: Wed, 07 Apr 2010 19:21:13 -0700

Dan,

http://blogs.sun.com/arungupta/entry/totd_124_using_cdi_jpa is an
example that shows how DAO can be injected in a JAX-WS or JAX-RS class.

Few differences from your example ...

- DAO interface and impl are the same class
- Everything is bundled together in a WAR file
- No EJB module

I'll try your packaging style but can you look through the above blog
and see if something is missing.

Thanks,
-Arun

On 4/7/10 6:48 PM, glassfish_at_javadesktop.org wrote:
> I created a simple EAR (attached with source) to illustrate what seems like a couple of bugs in either GF or Weld or both.
>
> My goal is to have:
> 1. an EJB module with an SLSB exposed as a web service
> 2. a JPA module with a Dao interface and a DaoImpl class
> I'd like the SLSB to use @Inject to inject the DaoImpl class, and I'd like the DaoImpl class to use @PersistenceContext to inject an EntityManager.
>
> I can find no approach that works. Everything I try results in one exception or another. I've tried with both GF 3.0 build 74.2 as well as the GF 3.1 nightly build from two nights ago.
>
> When I leave in the @Inject, I get this:
>
> Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001408 Injection point has unsatisfied dependencies. Injection point: field sample.service.UserService.userDao; Qualifiers: [@javax.enterprise.inject.Default()]
> at org.jboss.weld.bootstrap.Validator.validateInjectionPoint(Validator.java:276)
> at org.jboss.weld.bootstrap.Validator.validateBean(Validator.java:122)
> at org.jboss.weld.bootstrap.Validator.validateRIBean(Validator.java:141)
> at org.jboss.weld.bootstrap.Validator.validateBeans(Validator.java:331)
> at org.jboss.weld.bootstrap.Validator.validateDeployment(Validator.java:317)
> at org.jboss.weld.bootstrap.WeldBootstrap.validateBeans(WeldBootstrap.java:399)
> at org.glassfish.weld.WeldDeployer.event(WeldDeployer.java:178)
> ... 30 more
>
> If I comment out the @Inject and instantiate the DaoImpl like this:
>
> private UserDao userDao = new UserDaoImpl();
>
> and leave just the @PersistenceContext, then I get this:
>
> Caused by: java.lang.NullPointerException
> at sample.persistence.impl.UserDaoImpl.find(UserDaoImpl.java:16)
> ...
>
> So even though there's an empty beans.xml in both the EJB and JPA projects, CDI injection doesn't seem to happen at all in the JPA project, and it's broken in the EJB project.
>
> Anyone have any ideas? Am I doing something wrong, or do GF/Weld have some bugs to work out? I'd be happy to create issues for either or both.
>
> Many thanks,
> -Dan
> [Message sent by forum member 'theodan']
>
> http://forums.java.net/jive/thread.jspa?messageID=395812
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>

-- 
Blog: http://blogs.sun.com/arungupta
Twitter: http://twitter.com/arungupta