2.11.4. Generation of Canonical MetaModel classes

Annotation processing tool generates source code for a metamodel class given the annotated source code of persistent entity. This tool is invoked during compilation for JDK6 compiler if OpenJPA and JPA libraries are specified in the compiler -classpath option and Annotation processor option -Aopenjpa.metamodel=true is specified.

 $ javac -classpath path/to/openjpa-all.jar -Aopenjpa.metamodel=true mypackage/MyEntity.java

will generate source code for canonical meta-model class mypackage.MyEntity_. The source code is generated relative to the directory specified in -s option of javac compiler and defaulted to the current directory.

The Annotation Processor recognizes the following options specified in the command-line with -A (none of them are mandatory).

  • -Aopenjpa.log=TRACE|INFO|WARN|ERROR : The logging level. Default is WARN.

  • -Aopenjpa.source=<n> : where <n> denotes the integral number for Java source version of the generated code. Default is 6.

  • -Aopenjpa.naming=class name : fully-qualified name of a class implementing org.apache.openjpa.meta.MetaDataFactory that determines the name of a meta-class given the name of the original persistent Java entity class. Defaults to org.apache.openjpa.persistence.PersistenceMetaDataFactory which appends an underscore character (\_) to the original Java class name.

  • -Aopenjpa.header=<url> : A url whose content will appear as comment header to the generated file(s). Recognizes special value ASL for Apache Source License header as comment. By default, adds an OpenJPA proprietary text as comment block.

  • -Aopenjpa.addGeneratedAnnotation=auto|force|false : Configure whether the annotation jakarta.annotation.Generated should be added to the generated metamodel classes. This annotation is not available on Java 9 upwards unless the jakarta.annotation-api is in the classpath. The default is auto. Set to force to add the annotation even if it is not in the classpath or to false to never add it to the generated class.