Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ORMLite on Android using javax.persistence annotations

We have developed a web service and now are building an Android application to communicate with the web service. We use persistence in our web service and would also like to use persistence in our Android app. We figured that ORMLite was the way to go for persistency on Android and we are hoping that the javax.persistence support would be good enough for our app. I was hoping that I would be able to copy the web service's data model to the Android app and not having to modify the annotations.

So I tried copying the model classes and adding ormlite-android-4.41.jar and ormlite-core-4.41.jar to my Android project. Unfortunately this did not do the trick. My IDE can't find the classpaths for the javax.persistence annotations. Do I need additional libraries? I can't anything on that in the documentation.

like image 321
Jasper de Vries Avatar asked Aug 20 '12 08:08

Jasper de Vries


2 Answers

If you are using maven. You can add this to your pom.xml:

<dependency>
    <groupId>javax.persistence</groupId>
    <artifactId>persistence-api</artifactId>
    <version>1.0.2</version>
</dependency>

Alternatively you can download the jar file straight from the maven repository here then add it to the classpath. By the way, the @Table(name = "table_name") is not supported. You should substitute it with @Entity(name="table_name").

like image 73
Thunder Avatar answered Nov 19 '22 17:11

Thunder


Interesting question. If the javax.persistence annotations aren't in the Android JDK then I'm not sure you should be using them.

That said, if you want to use them, you should be able to get the java files from a JDK source jar and include them in your own project. Just copy the annotations that you actually use out of the source jar into the appropriate javax/persistence path.

The ORMLite support for the javax.persistence annotations is far from perfect. If you have any problems please let me know so I can improve them.

like image 35
Gray Avatar answered Nov 19 '22 16:11

Gray