【问题标题】:Android: EclipseLink: No Persistence provider for EntityManager named PUAndroid:EclipseLink:没有名为 PU 的 EntityManager 的持久性提供程序
【发布时间】:2013-04-22 09:19:47
【问题描述】:

我有一个 jpa 程序,我想在 android 上进行转换。这是我的 android 项目中的 src 文件结构:

+---org
|   \---manager
|       +---android
|       |       EnterIndexNumberActivity.java
|       |       MainActivity.java
|       |       WrongCredentials.java
|       |       
|       +---controller
|       |       DBStuff.java
|       |       ManagerMain.java
|       |       ServerHandling.java
|       |       
|       +---model
|       |       Person.java
|       |       
|       \---view
\---META-INF
        persistence.xml

这是我的 persistence.xml:

<?xml version="1.0" encoding="UTF-8"?>
<persistence version="2.0" 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_2_0.xsd">
  <persistence-unit name="PU" transaction-type="RESOURCE_LOCAL">
    <provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
    <class>itan.manager.model.Itan</class>
    <properties>          
      <property name="javax.persistence.jdbc.url" value="jdbc:h2:data/.h2/db/manager;CIPHER=AES;IFEXISTS=TRUE;"/>      
      <property name="javax.persistence.jdbc.user" value=""/>
      <property name="javax.persistence.jdbc.password" value=""/>
      <property name="javax.persistence.jdbc.driver" value="org.h2.Driver"/>
    </properties>
  </persistence-unit>
</persistence>

如果我想连接到数据库,则会抛出一个异常,即找不到名为“PU”的 EntityManager 的持久性提供程序。我必须做什么?我认为在设备上找不到persistence.xml。但是如何让类知道 xml 文件呢?

谢谢!

【问题讨论】:

    标签: android jpa eclipselink persistence.xml


    【解决方案1】:

    您的应用程序中是否已打包 JPA jar? (persistence.jar, eclipselink.jar)

    我不知道 JPA 可以在 Android 上运行。

    您可能需要直接访问持久化提供程序,并且可能需要传递一个类加载器。

    org.eclipse.persistence.jpa.PersistenceProvider.createEntityManagerFactory()
    

    看, http://www.eclipse.org/eclipselink/api/2.4/org/eclipse/persistence/config/PersistenceUnitProperties.html#CLASSLOADER

    【讨论】:

      猜你喜欢
      • 2018-11-28
      • 1970-01-01
      • 2015-11-08
      • 2016-04-18
      • 1970-01-01
      • 2019-12-04
      • 2014-03-03
      • 2016-08-02
      相关资源
      最近更新 更多