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.
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")
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With