0

i have a jpa programm which i wanted to tansform on android. this is the src-file-structure from my android project:

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

This is my 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>

If i want to connect to the database an ecxeption is thrown that No Persistence provider for EntityManager named "PU" was found. What i have to do? I think that the persistence.xml can not found on the device. but how to do that the classes know the xml-file?

thanks!

1 Answers1

0

Do you have the JPA jars packaged in your application? (persistence.jar, eclipselink.jar)

I was not aware that JPA worked on Android.

You may need to access the persistence provider directly, and may need to pass a class loader.

i.e.

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

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

James
  • 17,965
  • 11
  • 91
  • 146