Get Started

Add cmobilecom maven repository in your build.gradle:
repositories {	
	jcenter()
	mavenCentral()
	
	
	maven {
		url "https://cmobilecom.com/maven/repository/release"
	}
	
}
Artifacts: For example,

JDBC:

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

Android:
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

	android:sqlite:databseName

Identifier Equality

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

    @Override
    public boolean equals(Object o) {
        ...
    }
    
    @Override
    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,
	<non-jta-data-source>data-source-JNDI-name</non-jta-data-source>

Supported Databases

MySql, Oracle, Sqlite, Android Sqlite.

Limitations

Submit bug reports or new feature requests at https://cmobilecom.com.