我正在尝试建立一个基本的JPA。但我甚至无法得到EntityManger
。以下配置可能出现什么问题?
private static final EntityManager emf = Persistence
.createEntityManagerFactory("transactions-optional").createEntityManager();
src/META-INF/persistence.xml
(也尝试过: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>
结果:
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配置:
<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>
更新了配置:
<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>
答案 0 :(得分:2)
Google的datanucleus-appengine 2.1.x需要DataNucleus 3.1.x(而不是3.2.x)。 你应该有jdo-api v3.x(不是jdo2-api v2.3.x)。 如果使用JPA,则需要“datanucleus-api-jpa”v3.1.x(不是“datanucleus-jpa”v1.x)。 您还需要“geronimo-jpa-2.0_spec”v1.x(不是geronimo-jpa-3.0_spec v1.x)。
是的,我认为你完全可以messed up the dependencies ;-) 然后,当您修复了使用GAE docs设置持久性提供程序
时答案 1 :(得分:0)
我认为问题是提供者类
中缺少 l&LT;提供商GT; org.datanucleus.api.jpa.PersistenceProviderImp的升&LT; /提供商GT;
答案 2 :(得分:0)
我有同样的问题。查看META-INF,有两个名为:
的文件如果您正在使用持久性api,那么您可以通过在jdoconfig.xml文件中添加块注释来消除此错误