Glassfish 4.1.1 / EAR / java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName XYZ

314 views Asked by At

I have a huge problem deploying an EAR project on my Payara/Glassfish 4.1.1 server, which I can't solve since days.

Hope somebody can help me!

My setup -> I have one EJB/JPA eclipse project "CommonPersistanceAndService" that contains my JPA entities, my Databaseproducer, and some basic serviceclasses.

I have a webproject that uses this EJB/JPA project so I know that my databaseproducer works correctly:

@Singleton
@Startup
public class DatenbankProducer implements Serializable{

    private static final long serialVersionUID = 2605227297803488033L;

    @PersistenceContext(unitName="XYZdb")
    EntityManager emXYZProd;

    @PersistenceContext(unitName="XYZtest")
    EntityManager emXYZTest;

    @Inject ApplicationConfig appConfig;
    @Inject Logger logger;

    public XYZDatenbankProducer() { }

    @Produces 
    @XYZDatenbank
    public EntityManager getEntityManager(){
        if(appConfig.isBetriebsmodusTest())
            return emXYZTest;
        return emXYZProd;
    }

    @PostConstruct
    public void initDBConnection(){

        Query q = getEntityManager().createNativeQuery("select * from zconnectiontest");
        q.getSingleResult();

        logger.info("=== Connection to Database established");
    }
}

Now using this same EJB/JPA project in an EAR project together with a project "Batchjobs" that only has a serviceclass with a scheduler

<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd" version="6">
  <display-name>Batchjobs-EAR</display-name>
  <module>
    <ejb>Batchjobs.jar</ejb>
  </module>
  <module>
    <ejb>CommonPersistanceAndService.jar</ejb>
  </module>
</application>

I also copied all jar file dependencies from my EJB/JPA project to the EAR/lib directory. The EAR deploys correctly, but when the scheduler calls the service I get the following error:

Caused by: java.lang.IllegalStateException: Unable to retrieve EntityManagerFactory for unitName XYZtest
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.init(EntityManagerWrapper.java:138)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper._getDelegate(EntityManagerWrapper.java:171)
    at com.sun.enterprise.container.common.impl.EntityManagerWrapper.createNativeQuery(EntityManagerWrapper.java:557)
    at com.isg.kis.application.XYZDatenbankProducer.initDBConnection(XYZDatenbankProducer.java:48)
    ... 122 more

When I debug the programm the object for emXYZTest, a EntityManagerWrapper, doesn't get an EntityManagerFactory injected!? When I do the same in my Webproject there is an EntityManagerFactory. enter image description here

So the question is - why does the EntityManagerFactory not get injected in the EAR deployment!?

Nothing I tried so far worked. Any ideas what causes this problem?

thanks in advance

Thomas

0

There are 0 answers