简体   繁体   中英

No Persistence provider for EntityManager?

I'm trying to set up a basic JPA. But I cannot even get the EntityManger . What might be wrong with the following configuration?

private static final EntityManager emf = Persistence
.createEntityManagerFactory("transactions-optional").createEntityManager();

src/META-INF/persistence.xml (also tried: src/main/webapp/WEB-INF/classes/META-INF/ ):

<?xml version="1.0" encoding="UTF-8" ?>
<persistence xmlns="http://java.sun.com/xml/ns/persistence"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/persistence
        http://java.sun.com/xml/ns/persistence/persistence_1_0.xsd" version="1.0">

    <persistence-unit name="transactions-optional">
        <provider>org.datanucleus.api.jpa.PersistenceProviderImp</provider>
        <properties>
            <property name="datanucleus.NontransactionalRead" value="true"/>
            <property name="datanucleus.NontransactionalWrite" value="true"/>
            <property name="datanucleus.ConnectionURL" value="appengine"/>
        </properties>
    </persistence-unit>
</persistence>

Result:

Caused by: javax.persistence.PersistenceException: No Persistence provider for EntityManager named transactions-optional
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:54)
    at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
    at de.verism.server.database.EMFService.<clinit>(EMFService.java:13)

Maven Config:

   <dependency>
        <groupId>javax.jdo</groupId>
        <artifactId>jdo2-api</artifactId>
        <version>2.3-eb</version>
        <exclusions>
            <!--
                exclude the legacy javax.transaction:transaction-api
                and replace it with javax.transaction:jta (it
                appears to be the same thing)
            -->
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <dependency>
        <groupId>com.google.appengine.orm</groupId>
        <artifactId>datanucleus-appengine</artifactId>
        <version>2.1.2</version>
    </dependency>
    <dependency>
        <groupId>org.datanucleus</groupId>
        <artifactId>datanucleus-core</artifactId>
        <version>3.2.4</version>
        <exclusions>
            <exclusion>
                <groupId>javax.transaction</groupId>
                <artifactId>transaction-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>datanucleus-jpa</artifactId>
        <version>1.1.5</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>geronimo-jpa_3.0_spec</artifactId>
        <version>1.1.1</version>
        <scope>runtime</scope>
    </dependency>
    <dependency>
        <groupId>com.google.appengine</groupId>
        <artifactId>appengine-api-1.0-sdk</artifactId>
        <version>${gae.version}</version>
    </dependency>

Updated config:

        <dependency>
            <groupId>com.google.appengine.orm</groupId>
            <artifactId>datanucleus-appengine</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-core</artifactId>
            <version>3.1.1</version>
        </dependency>
        <dependency>
            <groupId>org.datanucleus</groupId>
            <artifactId>datanucleus-api-jpa</artifactId>
            <version>3.1.1</version>
        </dependency>
<dependency>
    <groupId>org.apache.geronimo.specs</groupId>
    <artifactId>geronimo-jpa_2.0_spec</artifactId>
    <version>1.1</version>
    <scope>runtime</scope>
</dependency>

Google's datanucleus-appengine 2.1.x requires DataNucleus 3.1.x (not 3.2.x). You should have jdo-api v3.x (not jdo2-api v2.3.x). If using JPA you need "datanucleus-api-jpa" v3.1.x (not "datanucleus-jpa" v1.x). You also then need "geronimo-jpa-2.0_spec" v1.x (not geronimo-jpa-3.0_spec v1.x).

Yes I think its fair to say that you've utterly messed up the dependencies ;-) then when you've fixed that you use GAE docs to set the persistence provider

I think the problem is the missing l at the provider class

<provider>org.datanucleus.api.jpa.PersistenceProviderImp </provider> </ provider>

I had the same issue. Look into the META-INF, there are two files named:

  • jdoconfig.xml
  • persistence.xml

If you are using persistence api, then you can get rid of this error by adding the block comment in the jdoconfig.xml file

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM