users@glassfish.java.net

CDI broken between EJB and JPA modules

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Apr 2010 18:48:16 PDT

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