wsmapping command
The wsmapping tool is used to provide top-down mapping of the entity object model to the database relational model. Use the wsmapping tool to create database tables.
Syntax
Before running the command, have a copy of persistence.xml on the class path, or specify it as a properties file in the -p [/path/to/persistence.xml] argument. Issue the command from the bin subdirectory of the profile_root directory.
The command syntax is as follows:
(zos)
wsmapping.sh [options][arguments]
(iseries)
wsmapping [options][arguments]
wsmapping.bat [options][arguments]
Parameters
The mapping tool accepts the standard set of command-line arguments defined by the configuration framework with the following options:
- schemaAction/-sa <add | refresh | drop | build | reflect | retain | createDB | import | export | none>: The action to implement against the schema.
These options correspond to the actions of the schema tool. Add is the default action if none is specified. Actions can be composed in a list separated by commas.
The wsmapping tool accepts the -action/-a flag to specify the action to take on individual classes. Unless you are running wsmapping on all of the persistent types at once, or dropping a mapping, use the default add action or the build action. Otherwise, you might inadvertently drop schema components used by classes that you are not currently running the tool against.
- schemaFile/-sf <true/t | false/f>: This option can be used to write the planned schema to an XML document rather than modify the database.
The XML document can then be modified, manipulated and committed to the database with the schema tool.
- sqlFile/-sql <stdout | output file>: This option can be used to write the planned schema modifications to an SQL script rather than modify the database.
Combine this parameter with a schemaAction of build to generate a script that recreates the schema for the current mappings, even if the schema exists.
- dropTables/-dt <true/t | false/f>: When this option is set to true, schema drops tables that appear to be unused during retain and refresh actions.
The default is true.
- dropSequences/-dsq <true/t | false/f>: If true, schema drops sequences that are unused during retain and refresh actions.
The default is true.
- openjpatables/-ot <true/t | false/f>: When reflecting the schema, this parameter determines whether to reflect on tables and sequences with names that start with OPENJPA_.
Certain OpenJPA components use these tables and sequences, such as the table schema factory. When using other actions, the openjpaTables parameter controls whether these tables can be dropped or not. The default setting is false.
- ignoreErrors/-i <true/t | false/f>: If set to false, an exception is occurs if the tool encounters database errors.
The default is set to false.
- schemas/-s <schema list>: Denotes a list of schema and table names the OpenJPA should access when running the wsschema tool.
This is the equivalent to setting the openjpa.jdbc.Schemas property to run once. This parameter corresponds to the -schemas/-s parameter in the wsschema tool. This option is ignored if -readSchema/-rs is not set to true.
- readSchema/-rs <true/t | false/f>: Set true to read the entire existing schema when the mapping tool runs.
Reading the existing schema ensures that OpenJPA does not generate any mappings that use the table, index, primary key or foreign key names that conflict with existing names.
Depending on the particular JDBC driver, selecting the -readSchema/-rs function can slow down the process for large schemas.
- primaryKeys/-pk <true/t | false/f>: This flag determines if the primary keys can be manipulated on existing tables.
The default is true.
- foreignKeys/fk <true/t | false/f>: This flag determines if foreign keys can be manipulated on existing tables.
The default is true. This means that to add a new foreign key to a class that has already been mapped, you must explicitly set this parameter flag to true.
- indexes/-ix <true/t | false/f>: This flag determines if indexes can be manipulated on existing tables.
The default is true. This means that to add new indexes to a class that has already been mapped, you must explicitly set this parameter flag to true.
- sequences/-sq <true/t | false/f>: This flag determines if sequences can be manipulated.
The default is true.
- meta/-m <true/t | false/f>: This flag determines whether a mapping applies to metadata rather than, or in addition to, standard mappings.
- The wsmapping tool accepts the -action/-a flag to specify the action to take on each class. Multiple actions can be composed in a list, separated by commas. The available actions are:
- buildSchema: This is the default action. The buildSchema action makes the database schema match the existing mappings. If the provided mappings conflict with the class definitions, OpenJPA fails with an informative exception.
- validate: Ensure that the mappings for the given classes are valid and that they match the schema of the database. No mappings of tables are changed as a result of this action. An exception occurs if any mappings are invalid.
Each additional argument to the wsmapping 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.
If we do not supply any arguments to the wsmapping tool, it runs on the classes in the persistent classes list.
Usage
Before running the wsmapping tool, configure the data source information, including the URL, user, and password. It is required that the wsenhancer tool is run before the wsmapping tool to insert bytecode into the entity classes. Also, the compiled class files for the entities should be on the class path. Assume that entity class files can be found in target/classes, for example:
(zos)
export CLASSPATH=${CLASSPATH}:target/classes wsmapping.sh ...
(iseries)
export CLASSPATH=${CLASSPATH}:target/classes wsmapping ...
SET CLASSPATH=%CLASSPATH%;target\classes wsmapping.bat . . .
To create tables, run the wsmapping command from the ${profile_root}/bin directory. When completed, the database tables are created or updated. Messages and errors are logged to the console as specified by log settings.
wsmapping.sh . . . On Windows :
By specifying the buildSchema parameter to the openjpa.jdbc.SynchronizeMappings property, the mapping tool provides the default mapping that matches with the database schema automatically. We are not required to run this mapping tool if the default mapping satisfies the necessary database schema.
Examples
To create the database tables needed for the Magazine.java file:
(zos)
${profile_root}/bin/wsmapping.sh Magazine.java
(iseries)
${profile_root}/bin/wsmapping Magazine.java
${profile_root}\bin\wsmapping.sh Magazine.java
To drop the tables for Magazine.java:
(zos)
C:\> %profile_root%/bin/wsmapping.sh -sa dropDB Magazine.java
(iseries)
C:\> %profile_root%/bin/wsmapping -sa dropDB Magazine.java
C:\> %profile_root%\bin\wsmapping.bat -sa dropDB Magazine.java
To validate the mappings for all classes on the class path:
(zos)
C:\> %profile_root%/bin/wsmapping.sh -a validate
(iseries)
C:\> %profile_root%/bin/wsmapping -a validate
C:\> %profile_root%\bin\wsmapping.bat -a validate
Additional information
See the mapping information in the Apache OpenJPA User Guide for more information and examples.
Develop JPA 2.x applications for a Java EE environment Develop JPA 2.x applications for a Java SE environment
Apache OpenJPA User's Guide