users@glassfish.java.net

WAR packaging, JPA and CDI question

From: <glassfish_at_javadesktop.org>
Date: Wed, 03 Mar 2010 05:23:45 PST

Hi.
I have been working to fix a solution for this issue: http://forums.java.net/jive/thread.jspa?threadID=74047&tstart=0 and wanted to test a scenario like this one:
1. there is a JPA module, that has the META-INF/persistence.xml file
2. EJB module that has 2 SLSBs, but use the persistence context from the unit defined in the first module ; bean1 uses @PersistenceContext injection, whereas bean2 uses @Inject; there is also a class with a @Produces @PersistenceContext field producer as shown in CDi specs. The JPA unit it has injected and provides is the same that bean1 uses - the one defined in module 1. This module has the file META-INF/beans.xml to turn bean discovery on.
3. WAR module that has only one servlet, and that contains both module 1 and 2 in WEB-INF/lib directory. It has also both bean1 and bean2 injected by means of @EJB.

Invoking bean1 (the one that uses the 'old' @PersistenceContext injection) works fine. Invoking bean2 (the one that uses CDI and the producer) results in an exception:

org.jboss.weld.NullInstanceException: WELD-000044 Unable to obtain instance from org.jboss.weld.bean-/home/rafal/Apps/glassfishv3/glassfish/domains/domain1/applications/TestWEB/-ProducerField-com.test.ejb.EntityManagerProducer.entityManager.

Is this a bug (the JPA unit is seen as bean1 works fine) or am I doing things wrong? According to the CDI specs, any jar inside WEB-INF/lib that has META-INF/beans.xml is a bean archive, and also the JPA unit is visible (as defined in JPA 2 specs), and yet it doesn't work. It behaves as though the bean archive defined in the EJB module couldn't use the JPA unit defined in another. Am I missing a beans.xml somewhere?

Best regards,
szczyp
[Message sent by forum member 'szczyp' (szczyp_at_gmail.com)]

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