Cmobilecom JPA 2.0.1 Developer Guide

4. Enhancer

Managed classes must be enhanced after compilation to be managed by EntityManager. The syntax of invoking Enhancer is:
	java -classpath classpath com.cmobilecom.jpa.processor.Enhancer
		-d outputDir -persistenceXmlClasspath persistence_xml_classpath
		class_root_directory1 class_root_directory2 ...
Enhance managed classes after they are compiled.

Java SE/Jakarta EE

Example: enhance managed classes in the source set "test".
configurations {
	processor
}
	
dependencies {
	// annotation processor: generate static metamodel
	processor 'com.cmobilecom:cmobilecom-jpa-processor:2.0.1'
}

// StaticMetamodelGenerator/Enhancer: classpath for loading META-INF/persistence.xml and 
// referenced orm mapping xml files.
def persistenceXmlClasspath = files('src/test/resources').asPath;
	
compileTestJava {
	// annotation processor: generate static metamodel source code which will be
	// added into sourceSet.java.srcDirs
	options.annotationProcessorPath = configurations.processor
	options.compilerArgs << '-ApersistenceXmlClasspath=' + persistenceXmlClasspath
	
	
	doLast {
		javaexec {
			classpath = configurations.processor
			main 'com.cmobilecom.jpa.processor.Enhancer'
			args "-persistenceXmlClasspath", persistenceXmlClasspath
			args sourceSets.test.output.classesDirs.singleFile.absolutePath
		}
	}
	
}

Android

Example: enhance managed classes in the source set "androidTest".
configurations {
	processor
}
	
dependencies {
	// annotation processor(static metamodel generator) and enhancer
	processor 'com.cmobilecom:cmobilecom-jpa-processor:2.0.1'

	// Android does not have javax.annotation that is required to compile generated sources,
	// but it is not needed at runtime.
	compileOnly group: 'javax.annotation', name: 'javax.annotation-api', version: '1.3.2'
	annotationProcessor configurations.processor
}
	
afterEvaluate {
	// StaticMetamodelGenerator/Enhancer: classpath for loading META-INF/persistence.xml and 
	// referenced orm mapping xml files.
	def persistenceXmlClasspath = files('src/androidTest/resources').asPath;

	compileDebugAndroidTestJavaWithJavac {
		options.compilerArgs << '-ApersistenceXmlClasspath=' + persistenceXmlClasspath

		
		doLast {
			javaexec {
				classpath = configurations.processor
				main 'com.cmobilecom.jpa.processor.Enhancer'
				args "-persistenceXmlClasspath", persistenceXmlClasspath
				args compileDebugAndroidTestJavaWithJavac.destinationDir
			}
		}
		
	}
}
The enhancer transforms classes (not jar) at build time. Do not add cmobilecom-jpa-processor.jar in runtime classpath. Added member (field or method) names have prefix "_jpa_". Keep those names if code is obfuscated (e.g., proguard).

Kotlin DSL

val processor by configurations.creating

dependencies {
	processor("com.cmobilecom:cmobilecom-jpa-processor:2.0.1")

	// annotation processor: generate static metamodel
	// Android does not have javax.annotation that is required to compile generated sources
	// but it is not needed runtime.
	compileOnly("javax.annotation:javax.annotation-api:1.3.2")
	annotationProcessor(processor)
}

afterEvaluate {

	// static metamodel generation and enhancement: classpath for loading META-INF/persistence.xml
	// and referenced orm mapping xml files.
	val persistenceXmlClasspath = files(android.sourceSets["main"].resources.srcDirs).asPath

	val compileDebugJavaWithJavac = tasks.named<JavaCompile>("compileDebugJavaWithJavac");
	compileDebugJavaWithJavac {
		options.compilerArgs.add("-ApersistenceXmlClasspath=" + persistenceXmlClasspath)

		
		doLast {
			javaexec {
				classpath = processor
				main = "com.cmobilecom.jpa.processor.Enhancer"
				args("-persistenceXmlClasspath", persistenceXmlClasspath)
				args(compileDebugJavaWithJavac.get().destinationDir)
			}
		}
		
	}
}
See build scripts that put together compile dependencies, runtime dependencies, static metamodel generation and managed class enhancement.
Static Metamodel GenerationSchema GenerationFrames / No Frames