javax.persistence.EntityManager is null in payara micro 5.182

749 views
Skip to first unread message

Craig Main

unread,
Jul 20, 2018, 2:05:55 PM7/20/18
to Payara Forum
I am battling to setup payara micro with postgres, and injecting an entity manager.

My problem is that if I create the connection manually, it seems to work.
The entity manager doesn't want to inject though.

The entity manager below is always null.
When payara micro starts up, it doesn't seem to scan the entities.



@RequestScoped @Path("") public class QualityMeasurementQueryFacade { @PersistenceContext(unitName = "pcc") private EntityManager entityManager; @GET @Path("query") @Produces(MediaType.TEXT_PLAIN) public String testSimpleQuery() { QualityMeasurementEntity entity = new QualityMeasurementEntity(); entity.setBrand("TEST"); entityManager.persist(entity); entityManager.flush(); return "DONE!"; } }

I have included the relevant xml files, 

META-INF\persistence.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             version="2.1"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="pcc" transaction-type="JTA">
        <jta-data-source>java:app/jdbc/pcc</jta-data-source>
        <class>com.xxx.pcc.entity.QualityMeasurementEntity</class>
        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.schema-generation.database.action" value="create"/>
        </properties>
    </persistence-unit>

</persistence>

WEB-INF\glassfish-resources.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE resources PUBLIC
        "-//GlassFish.org//DTD GlassFish Application Server 3.1 Resource Definitions//EN"
        "http://glassfish.org/dtds/glassfish-resources_1_5.dtd">

    <resources>
        <jdbc-connection-pool
                datasource-classname="org.postgresql.ds.PGPoolingDataSource" name="PCCPool"
                res-type="javax.sql.DataSource"
                steady-pool-size="1"
                is-connection-validation-required="true"
                connection-validation-method="meta-data"
                max-pool-size="10">
            <property name="password" value="postgres"/>
            <property name="user" value="postgres"/>
            <property name="databaseName" value="pcc"/>
            <property name="serverName" value="localhost"/>
            <property name="portNumber" value="5432"/>
        </jdbc-connection-pool>
        <jdbc-resource pool-name="PCCPool" jndi-name="jdbc/pcc"/>

    </resources>


What else needs to be done to ensure that the @Entities are scanned, and the EntityManager injected





Craig Main

unread,
Jul 20, 2018, 2:09:36 PM7/20/18
to Payara Forum
I have tried a more comprehensive persistence.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             version="2.1"
             xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_1.xsd">

    <persistence-unit name="pcc" transaction-type="JTA">

        <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
        <jta-data-source>java:app/jdbc/pcc</jta-data-source>
        <class>com.bmw.pcc.entity.QualityMeasurementEntity</class>

        <exclude-unlisted-classes>false</exclude-unlisted-classes>
        <properties>
            <property name="javax.persistence.schema-generation.database.action" value="create"/>

            <property name="javax.persistence.jdbc.driver" value="org.postgresql.Driver" />
            <property name="javax.persistence.jdbc.url" value="jdbc:postgresql://localhost:5432/mcp" />
            <property name="javax.persistence.jdbc.user" value="postgres" />
            <property name="javax.persistence.jdbc.password" value="postgres" />
            <property name="eclipselink.deploy-on-startup" value="true"/>
            <property name="eclipselink.logging.level" value="INFO"/>
            <property name="eclipselink.logging.level.sql" value="OFF"/>
            <property name="eclipselink.jdbc.fetch-size" value="1000"/>
            <property name="eclipselink.logging.parameters" value="true"/>
            <property name="eclipselink.query-results-cache" value="true"/>
            <property name="eclipselink.jdbc.cache-statements" value="true"/>
            <property name="eclipselink.persistence-context.flush-mode" value="commit"/>
            <property name="eclipselink.ddl-generation.output-mode" value="database"/>
        </properties>
    </persistence-unit>

</persistence>

Craig Main

unread,
Jul 21, 2018, 12:10:34 PM7/21/18
to Payara Forum
Is this a bad question for some reason is more detail needed somehow?
Reply all
Reply to author
Forward
0 new messages