+

Search Tips   |   Advanced Search

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.


Syntax

Before running the command, we must 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:

(UNIX) (ZOS)

wsmapping.sh [options][arguments]
(iSeries)
wsmapping [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:

Each additional argument to the wsmapping tool must be one of the following:

If we do not supply any arguments to the wsmapping tool, it runs on the classes in the persistent classes list.

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 our entities should be on the class path. Assume that entity class files can be found in target/classes, for example:

(AIX) (HPUX) (Linux) (UNIX) (Solaris) (ZOS)

export CLASSPATH=${CLASSPATH}:target/classes 

wsmapping.sh ...
(iSeries)
export CLASSPATH=${CLASSPATH}:target/classes 

wsmapping ...
(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 administrative 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. 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:

(UNIX) (ZOS)

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

To drop the tables for Magazine.java:

(UNIX) (ZOS)

C:\> %profile_root%/bin/wsmapping.sh -sa dropDB Magazine.java
(iSeries)
C:\> %profile_root%/bin/wsmapping -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:

(UNIX) (ZOS)

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

  • Developing JPA 2.x applications for a Java EE environment
  • Developing JPA 2.x applications for a Java SE environment
  • Apache OpenJPA User's Guide