wsmapping command
The wsmapping tool is used to provide top-down mapping of the entity object model to the database relational model. You can use the wsmapping tool to create database tables.
Syntax
The command syntax is as follows:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
wsmapping.sh [options][arguments]
![[IBM i]](../images/iseries.gif)
wsmapping [options][arguments]
![[Windows]](../images/windows.gif)
wsmapping.bat [options][arguments]
Parameters
- -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.
Note: 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 your persistent types at once, or dropping a mapping, you must use the default add action or the build action. Otherwise, you might inadvertently drop schema components that are 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 this option is set to 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 this option to 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.
Note: 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 your 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.
- The full name of a persistent class.
- The .java name for a persistent class.
- The .class file of a persistent class.
If you 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, you must 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 your entities should be on the class path. Assume that entity class files can be found in target/classes, for example:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[AIX HP-UX Solaris]](../images/unix.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
export CLASSPATH=${CLASSPATH}:target/classes
wsmapping.sh ...
![[IBM i]](../images/iseries.gif)
export CLASSPATH=${CLASSPATH}:target/classes
wsmapping ...
![[Windows]](../images/windows.gif)
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 administrative console as specified by log settings.
wsmapping.sh . . . On Windows :
Examples
To create the database tables needed for the Magazine.java file:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
${profile_root}/bin/wsmapping.sh Magazine.java
![[IBM i]](../images/iseries.gif)
${profile_root}/bin/wsmapping Magazine.java
![[Windows]](../images/windows.gif)
${profile_root}\bin\wsmapping.sh Magazine.java
To drop the tables for Magazine.java:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
C:\> %profile_root%/bin/wsmapping.sh -sa dropDB Magazine.java
![[IBM i]](../images/iseries.gif)
C:\> %profile_root%/bin/wsmapping -sa dropDB Magazine.java
![[Windows]](../images/windows.gif)
C:\> %profile_root%\bin\wsmapping.bat -sa dropDB Magazine.java
To validate the mappings for all classes on the class path:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
C:\> %profile_root%/bin/wsmapping.sh -a validate
![[IBM i]](../images/iseries.gif)
C:\> %profile_root%/bin/wsmapping -a validate
![[Windows]](../images/windows.gif)
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.