users@glassfish.java.net

Re: CDI broken between EJB and JPA modules

From: Sahoo <Sahoo_at_Sun.COM>
Date: Thu, 08 Apr 2010 23:18:39 +0530

Hi Dan,

The ear you have attached has separate jar with JPA classes and EJB
classes. I don't think that would work. So, first you need to merge
JPA.jar with EJB.jar. I guess you have already tried that
unsuccessfully. That's where the bug comes in. The persistence deployer
in GlassFish is thinking that there is no component in the EAR using the
persistence-unit, so it does not initialize it. Obviously that's a bug.
It is not parsing managed beans. As a simple work around, do the
following in your UserService.java:


@LocalBean
@Stateless
@WebService
public class UserService {
* // This is present to ensure that persistence-unit is loaded.
This is a work around to glassfish bug.
        @javax.persistence.PersistenceContext
javax.persistence.EntityManager em;
*

This will cause the persistence unit to be loaded and once that happens,
it will be successfully injected into the DAO managed bean as well. Give
it a try. File a bug if this's the case.

Thanks,
Sahoo

glassfish_at_javadesktop.org wrote:
> 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
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_glassfish.dev.java.net
> For additional commands, e-mail: users-help_at_glassfish.dev.java.net
>
>