users@glassfish.java.net

Re: CDI broken between EJB and JPA modules

From: <glassfish_at_javadesktop.org>
Date: Wed, 07 Apr 2010 20:56:34 PDT

Thanks for the quick reply, Arun.

I should mention that I've also tried merging the JPA module into the EJB module (I'm attaching another EAR with source that shows this). In that case, the @Inject works fine but the @PersistenceContext gives this:

Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName null
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:122)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:163)
        at com.sun.enterprise.container.common.impl.EntityManagerWrapper.find(EntityManagerWrapper.java:310)
        at sample.persistence.impl.UserDaoImpl.find(UserDaoImpl.java:16)
        at sample.service.UserService.loginByGuid(UserService.java:20)
        ...

If I move the @PersistenceContext into the SLSB, it works fine there. So my persistence unit seems to be configured correctly, but it doesn't seem to be visible to non-EJB classes that rely on CDI for injection.

I've also tried @PersistenceContext(unitName="Admin") and the same thing happens (with the exception message mentioning "Admin" instead of null).

Surely a simple EAR with a single EJB module using two simple injections should be easily handled by GF and Weld. These various scenarios, all resulting in one exception or another, are why I suspect GF and Weld have some module interoperability kinks to work out.

I did come across your blog posts during my extensive googling into these issues, but nothing jumped out at me the first time. I will take a closer look though.

In the meantime, please feel free to try either one of the EARs I've attached, and let me know if either of these simple scenarios work for you.

Thanks again,
-Dan
[Message sent by forum member 'theodan']

http://forums.java.net/jive/thread.jspa?messageID=395825