Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JPA Annotations in Android

We have a project that uses JPA/Hibernate on the server side, the mapped entity classes are in their own Library-Project and use Annotations to be mapped to the database. I want to use these classes in an Android-Project - is there any way to ignore the annotations within Android, to use these classes as standard POJOs?

like image 339
dasmaze Avatar asked Oct 27 '09 14:10

dasmaze


People also ask

What are Annotations in Android?

Annotations allow you to provide hints to code inspections tools like Lint, to help detect these more subtle code problems. They are added as metadata tags that you attach to variables, parameters, and return values to inspect method return values, passed parameters, local variables, and fields.

What is @embedded annotation?

The JPA annotation @Embedded is used to embed a type into another entity.


1 Answers

You can use Cmobilecom JPA for android and java. It implements JPA 2.1 specification. So all your JPA annotations for java will work for android without any changes. Simply add the following dependencies in your projects.

Android:

dependencies {
    implementation("com.cmobilecom:cmobilecom-jpa-android:${version}@aar") {
        transitive = true
    }

    annotationProcessor "com.cmobilecom:cmobilecom-jpa-processor:$version"
}

JDBC:

dependencies {
    implementation "com.cmobilecom:cmobilecom-jpa-jdbc:$version"

    // annotation processor: generate static metamodel
    compileOnly "com.cmobilecom:cmobilecom-jpa-processor:$version"
}

Disclaimer: I am a developer of Cmobilecom JPA.

like image 116
John Avatar answered Sep 19 '22 02:09

John