The JPA specification allows an entity's primary key to be made up of more than one column. In this case, the primary key is referred to as a "composite" or "compound" primary key. You need to provide an ID class, which is specified by the @IdClass annotation, in order to manage a composite primary key. Use the identity tool for JPA to generate an ID class for entities that use composite primary keys.
The command syntax is as follows:
wsappid.sh [parameters][arguments]
wsappid [parameters][arguments]
wsappid.bat [parameters][arguments]
Before running the command, you must have a copy of persistence.xml on the classpath, or specify it as a properties file via the -p [path_to_persistence.xml] argument. Issue the command from the bin subdirectory of the app_server_root directory.
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 refers to an identity that uses more than one field as its primary key. The entity class must be compiled, and primary keys need to be identified in the entity class. Run the wsappid tool from the command line in the app_server_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.
@Entity public class Employee { @Id private int division; @Id private int id; // . . . }Before the entity can be used we need an ID class. 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:
wsappid.sh -s Id src/main/java/Employee.java -d src/main/java
wsappid -s Id src/main/java/Employee.java -d src/main/java
wsappid.bat -s Id src\main\java\Employee.java -d src\main\javaA new class, EmployeeId.java, will be generated in the src/main/java directory.
You can refer to the Application identity tool in persistence classes in the Apache OpenJPA User's Guide.