The schema tool can be used to view the database schema
in XML form or match an XML schema to an existing database.
The wsschema tool can reflect on the current database schema, optionally
translating it into an XML representation for further manipulation.
Also, the schema tool can take an XML schema definition, calculate
the differences between the XML and the existing database schema,
and apply the necessary changes to make the databases correspond to
the XML schema. The XML format used by the schema tool is abstract
from the differences in SQL dialects used by different vendors. The
tool also automatically adapts its SQL to meet foreign dependencies,
thus the schema tool is useful as a general way to manipulate the
schemas.
The Feature Pack
for OSGi Applications and JPA 2.0 introduces support for Apache OpenJPA
2.0.
Run the JPA commands
(.bat on Windows or .sh on UNIX) from the <profile_root>/bin directory,
rather than from the <app_server_root>/bin directory to make sure
you have the latest version of the commands for your release level.
Parameters
The wsschema tool accepts the
standard set of command-line arguments defined by the configuration
framework along with the following:
- -ignoreErrors/-i <true/t | false/f>:
If set to false, an exception will be thrown if the tool encounters
any database errors. The default is set to false.
- -file/-f <stdout | output file>:
Use this option to write a SQL script for the planned schema modifications,
rather than committing them to the database. When this is used in
conjunction with the export or reflect actions, the named file will
be used to write the exported schema XML. If the file names a resource
in the CLASSPATH, data will be written to that resource. Use stdout
to write to standard output. The default setting is stdout.
- -openjpatables/-ot <true/t | false/f>:
When reflecting the schema, this parameter determines whether to reflect
on tables and sequences whose names start with OPENJPA_. Certain OpenJPA
components may use such tables and sequences, such as the table schema
factory. When using other actions, openjpaTables controls whether
these tables can be dropped or not. The default setting is false.
- -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 appear to be unused during retain and refresh actions.
The default is true.
- -sequences/-sq <true/t | false/f>:
This flag determines if sequences may be manipulated. The default
is true.
- -indexes/-ix <true/t | false/f>:
This flag determines if indexes may be manipulated on existing tables.
The default is true.
- -primaryKeys/-pk <true/t | false/f>:
This flag determines if primary keys may be manipulated on existing
tables. The default is true.
- -foreignKeys/-fk <true/t
| false/f>: This flag determines if foreign keys may be
manipulated on existing tables. The default is true.
- -record/-r <true/t | false/f>:
This flag permits or prevents writing schema changes made by the schema
tool to the current schema factory. Select true to permit writing
schema changes or false to prevent writing schema changes. The default
is set to true.
- -schemas/-s <schema list>:
Denotes a list of schema and table names the OpenJPA should access
when running the schema tool. This is the equivalent to setting the
openjpa.jdbc.Schemas property to run once.
Important: The
schema tool accepts the
-action/-a flag. Multiple
actions may be composed in a list, separated by commas. The available
actions are:
Usage
The wsschema tool is used to obtain
a XML file that describes the schema of your database. To generate
a XML schema file:
- You need to have database tables and your database connection
configured.
Run the wsschema
tool from the command line in the <profile_root>/bin directory.
- The tool will generate a XML file that describes the database
schema.
Messages and errors are logged to the console as specified by
the configuration.
Additional information
For more information,
refer to chapter 4 JDBC, in the Apache OpenJPA reference documentation.