Network Deployment (Distributed operating systems), v8.0 > Reference > Command-line utilities


wsmapping command

The wsmapping tool is used to provide top-down mapping of the entity object model to the database relational model. We can use the wsmapping tool to create database tables.

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:

(AIX) (Solaris)

wsmapping.sh [options][arguments]
(Windows)
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 your persistent types at once, or dropping a mapping, 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.

    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 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 to add new indexes to a class that has already been mapped, 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.

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 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, 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) (Solaris)

export CLASSPATH=${CLASSPATH}:target/classes

wsmapping.sh ...
(Windows)
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 admin console as specified by log settings.

wsmapping.sh . . . On Windows :

Tip: 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. You 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:

(AIX) (Solaris)

${PROFILE_ROOT}/bin/wsmapping.sh Magazine.java
(Windows)
${PROFILE_ROOT}\bin\wsmapping.sh Magazine.java

To drop the tables for Magazine.java:

(AIX) (Solaris)

C:\> %PROFILE_ROOT%/bin/wsmapping.sh -sa dropDB Magazine.java
(Windows)
C:\> %PROFILE_ROOT%\bin\wsmapping.bat -sa dropDB Magazine.java

To validate the mappings for all classes on the class path:

(AIX) (Solaris)

C:\> %PROFILE_ROOT%/bin/wsmapping.sh -a validate
(Windows)
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.


Related


Develop JPA 2.x applications for a Java EE environment
Develop JPA 2.x applications for a Java SE environment

+

Search Tips   |   Advanced Search