wsappid command
The Java Persistence API (JPA) specification supports an entity primary key to be made up of more than one column. In this case, the primary key is called a composite or compound primary key. Provide an ID class, specified by the @IdClass annotation, to manage a composite primary key. Use the identity tool for JPA to generate an ID class for entities that use composite primary keys.
Syntax
Before running the command, have a copy of the persistence.xml file on the classpath, or specify it as a properties file in the -p [/path/to/persistence.xml] argument.
cd profile_root/bin
wsappid.sh [parameters][arguments]
The wsappid tool accepts the standard set of command-line arguments defined by the configuration framework along with the following:
- directory/-d <output_directory>:
The path to the output directory.
If the directory does not match the generated output ID class package, the package structure is created beneath the directory. If this parameter is not specified, the wsappid tool attempts to find the directory of the .java file for the class that supports persistence. If a .java file is not found, the wsappid tool uses the current directory.
- ignoreErrors/-i <true/t | false/f>:
If set to false, an exception is occurs when the tool is run on any class that does not use the application identity. An error also occurs if any class does not have the base class in the inheritance hierarchy.
- token/-t <token>:
The token used to separate the values of strung primary keys in the string form of the object ID.
Use this option only if there are multiple primary key fields. The default is "::".
- name/-n <id_class_name>:
The name of the identity class to generate.
If this option is specified, the wsappid tool must run on exactly one class. If the class metadata already names an ID class for the object, this option is ignored. If the name is not fully qualified, the package of the persistence class is appended to form the fully qualified name.
- suffix <id_class_suffix>:
A string with which to suffix each persistent class name to form the identity class name.
This option is overridden by the -name/-n parameter or by any object ID class specified in the metadata.
Each additional argument to the wsappid tool must be one of the following:
- The full name of a persistent class.
- The .java name for a persistent class.
- The .class file of a persistent class.
Usage
The identity tool used with JPA for application server simplifies the task of creating an identity class for entities that use composite IDs. A composite ID is an identity with more than one field as its primary key. The entity class must be compiled, and primary keys must be identified in the entity class. Run the wsappid tool from the command line in the profile_root/bin/ directory. When you run this command, a new class representing the composite ID of the entity is generated. Messages and errors are logged to the console as specified.
Examples
Consider the following entity:
@Entity public class Employee { @Id private int division; @Id private int id; // . . . }Before the entity is used, an ID class is needed. For this example, assume that the entity is found in the src/main/java directory.To generate an ID class for the Magazine entity run the following:
wsappid.sh -s Id src/main/java/Employee.java -d src/main/java
A new class, EmployeeId.java, is generated in the src/main/java directory.
Additional information
Read the Application identity tool in persistence classes information in the Apache OpenJPA User Guide for more information.
Related