Search code examples
javaandroidjavafxpersistence

Sharing model classes between pure java and Android


I am writing simple application that has Android client and java backend.

I want to create common library for those two applications that includes model classes used for communicatin between those. However, both apps store those information i own database and thats where is the problem. I cant use JNDI with normal ORM framework in java, because i cant use that in Android. I also cannot use Realm or Room for persistence in Android, because i cant use those in normal java.

So, what should I do? Do I just ditch the idea of common library, copy-paste those classes and just change annotations to work with different framework, or is there something usable with both platforms? (actually i hoped that Realm would work for normal java, but that is not the case...).


Solution

  • You may use JDX for Java and JDXA for Android ORM products and share the object model definitions without any changes. JDX and JDXA have a similar way of defining the mapping specification declaratively in a text file. No need of annotations. Both products have similar APIs.

    So you can have a virtually portable data access layer of your application for both the Java and the Android platforms. Disclaimer: I am the architect of JDX and JDXA ORMs.