3.6.4.3. Application Identity Tool
If you choose to use application identity, you may want to take advantage of OpenJPA’s application identity tool. The application identity tool generates Java code implementing the identity class for any persistent type using application identity. The code satisfies all the requirements the specification places on identity classes. You can use it as-is, or simply use it as a starting point, editing it to meet your needs.
Before you can run the application identity tool on a persistent class, the class must be compiled and must have complete metadata. All primary key fields must be marked as such in the metadata.
In JPA metadata, do not attempt to specify the @IdClass annotation unless you are using the application identity tool to overwrite an existing identity class.
Attempting to set the value of the @IdClass to a non-existent class will prevent your persistent class from compiling.
Instead, use the -name or -suffix options described below to tell OpenJPA what name to give your generated identity class.
Once the application identity tool has generated the class code, you can set the @IdClass annotation.
The application identity tool can be invoked via its Java class, org.apache.openjpa.enhance.ApplicationIdTool.
|
|
Application Identity Tool Ant Task describes the application identity tool’s Ant task. |
java org.apache.openjpa.enhance.ApplicationIdTool -s Id Magazine.java
The application identity tool accepts the standard set of command-line arguments defined by the configuration framework (see Command Line Configuration), including code formatting flags described in Code Formatting. It also accepts the following arguments:
-
-directory/-d <output directory>: Path to the output directory. If the directory does not match the generated oid class' package, the package structure will be created beneath the directory. If not specified, the tool will first try to find the directory of the .java file for the persistence-capable class, and failing that will use the current directory. -
-ignoreErrors/-i <true/t | false/f>: Iffalse, an exception will be thrown if the tool is run on any class that does not use application identity, or is not the base class in the inheritance hierarchy (recall that subclasses never define the application identity class; they inherit it from their persistent superclass). -
-token/-t <token>: The token to use to separate stringified primary key values in the string form of the object id. This option is only used if you have multiple primary key fields. It defaults to "::". -
-name/-n <id class name>: The name of the identity class to generate. If this option is specified, you must run the tool on exactly one class. If the class metadata already names an object id class, this option is ignored. If the name is not fully qualified, the persistent class' package is prepended to form the qualified name. -
-suffix/-s <id class suffix>: A string to suffix each persistent class name with to form the identity class name. This option is overridden by-nameor by any object id class specified in metadata.
Each additional argument to the tool must be one of the following:
-
The full name of a persistent class.
-
The .java file for a persistent class.
-
The .class file of a persistent class.
If you do not supply any arguments to the tool, it will act on the classes in your persistent classes list (see Persistent Class List).