Get Started

Add cmobilecom maven repository in your build.gradle:
repositories {	
	maven {
		url ""
Artifacts: For example,


dependencies {
	implementation 'com.cmobilecom:cmobilecom-jpa-jdbc:1.1.1'
	// annotation processor: generate static metamodel
	compileOnly 'com.cmobilecom:cmobilecom-jpa-processor:1.1.1'

dependencies {
	implementation('com.cmobilecom:cmobilecom-jpa-android:1.1.1@aar') {
		transitive = true

	annotationProcessor 'com.cmobilecom:cmobilecom-jpa-processor:1.1.1'
See build.gradle of the examples for detail.

EntityManagerFactory and EntityManager

Create an EntityManagerFactory for one persistence unit for JDBC or android as followings:
	import com.cmobilecom.jpa.Constants;
	Map<String, Object> properties = new HashMap<String, Object>();
	// JDBC or android, not both
	// JDBC properties
	properties.put(Constants.JDBC_USER, "test");
	properties.put(Constants.JDBC_PASSWORD, "123456");
	properties.put(Constants.JDBC_URL, "jdbc:mysql://localhost:3306/jpa_example_db?useSSL=false");

	// android 
	Context context = ...  // application context or activity
	properties.put(Constants.ANDROID_CONTEXT, context);
	properties.put(Constants.ANDROID_CONNECTION_URL, "android:sqlite:jpa_example_db");
	EntityManagerFactory emf = Persistence.createEntityManagerFactory("pu_name", properties);
	EntityManager em = emf.createEntityManager();

Database connection properties can be set in META-INF/persistence.xml or set at runtime. Properties set at runtime override those in META-INF/persistence.xml. If android context property (Constants.ANDROID_CONTEXT) is specified, android built-in sqlite database will be used and JDBC properties (if any) will be ignored.

The connection URL for android sqlite database is


Identifier Equality

IdClass and Embedded Id types must implement equals and hashCode methods for entity equality test.

    public boolean equals(Object o) {
    public int hashCode() {
If entity, embeddable or basic type is used as Map key, it must implement equals and hashCode methods.

Lazy Initialization

The fetch type of all the associations and element collections should be declared as LAZY to minimize the loading of object graph. Lazy attributes will be initialized dynamically on demand even if its entity is detached and its associated entity manager is closed.

Connection Pooling

Configure a data source that supports connection pooling, and specify it in META-INF/persistence.xml. For example,

Supported Databases

MySql, Oracle, Sqlite, Android Sqlite.


Submit bug reports or new feature requests at