The wsreversemapping tool generates persistent class definitions
and metadata from a database schema.
newfeatThe Feature Pack
for OSGi Applications and JPA 2.0 introduces support for Apache OpenJPA
2.0.
newfeatRun 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 wsreversemapping tool accepts
the standard set of command-line arguments defined by the configuration
framework along with the following:
- -schemas/-s <schema and table
names>: A list of schema and table names, separated by
commas, to run the reversmapping tool on if no XML schema file is
supplied. Each element of the list must follow the naming conventions
for the openjpa.jdbc.Schemas property. If this parameter flag is omitted,
it defaults to the value of the Schemas property.
If the Schemas property is not defined, then
all schemas will be reverse mapped.
- -package/-p <package name>:
The package name of the generated classes. If no package name is given,
the generated code will not contain package declarations.
- -directory/-d <output directory>:
All generated code and metadata will be written to the directory at
this path. If the path does not match the package of a class, the
package structure will be created beneath this directory. This parameter
defaults to the current directory.
- -useSchemaName/-sn <true/t | false/f>:
Set this parameter flag to true to include the schema as well as the
table name in the name of each generated class. This can be useful
when dealing with multiple schemas that have tables with identical
names.
- -useForeignKeyName/-fkn <true/t
| false/f>: Set this parameter flag to true if you want
the field names for relations to be based on the database foreign
key name. By default, relation field names are derived from the name
of the related class.
- -nullableAsObject/-no <true/t
| false/f>: By default, all non-foreign key columns are
mapped to primitives. Set this parameter flag to true to generate
primitive wrapper fields instead for columns that allow null values.
- -blobAsObject/-bo <true/t | false/f>:
By default, all binary columns are mapped to the byte[] fields. Set
this parameter flag to true to map them to Object fields instead.
Note: When
mapped this way, the column is presumed to contain a serialized Java object.
- -primaryKeyOnJoin/-pkj <true/t
| false/f>: The standard reverse mapping tool behavior
is to map all tables with primary keys to persistent classes. If your
schema has primary keys on many join tables as well, set this flag
to true to avoid creating classes for those tables.
- -inverseRelations/-ir <true/t
| false/f>: Set this parameter flag to false to prevent
the creation of inverse one-to-many/one-to-one relations for every
many-to-one/one-to-one relation detected.
- -useDatastoreIdentity/-ds <true/t
| false/f>: Set to true to use datastore identity for
tables that have single numeric primary key columns. The tool typically
uses application identity for all generated classes.
- -useBuiltinIdentityClass/-bic <true/t
| false/f>: Set this parameter flag to false to prevent
the reversemapping tool from using built-in application identity classes
when possible. This will force the tool to create custom application
identity classes even when there is only one primary key column.
- -innerIdentityClasses/-inn <true/t
| false/f>: Set this parameter flag to true to have any
generated application identity classed be created as static inner
classes within the persistent classes. The default setting is false.
- -identityClassSuffix/-is <suffix>:
Suffix to append to the class names to form application identity class
names, or for inner identity classes, the inner class name. The default
suffix is Id.
- -typeMap/-typ <type mapping>:
A string that specifies the default Java classes
to generate for each SQL type that is seen in the schema. The format
is SQLTYPE1=JavaClass1, SQLTYPE2=JavaClass2. The SQL type name first
looks for a customization that is based on SQLTYPE(SIZE,PRECISION),
then SQLTYPE(SIZE), and then SQLTYPE. If a column with type CHAR is
found, it will first look for the CHAR(50,0) type name specification,
then it will look for the CHAR(50), and finally it will look for the
CHAR. For example, to generate a char array for every char column
whose size is exactly 50 characters, and to generate a short for every
type name of INTEGER, you might specify: CHAR(50)=char[],INTEGER=short.
Note: Various
databases report different type names differently, one database type
may not work for another database. Enable TRACE level logging on the
MetaData channel to track which type names JPA for WebSphere® Application
Server is examining.
- -customizerClass/-cc <class name>:
The full class name of an org.apache.openjpa.jdbc.meta.ReverseCustomizer
customization plugin. If you do not specify a reverse customizer of
your own, the system defaults to a PropertiesReverseCustomizer. This
customizer allows you to specify simple customization options in the
properties file given with the -customizerProperties flag.
- -customizerProperties/-cp<properties
file or resource>: The path or resource name of a properties
file to pass to the reverse customizer on initialization.
- -customizer/-c <property name> <property
value>: The given property name will be matched with
the corresponding Java bean property in the specified
reverse customizer, and set to the given value.
Usage
The wsreversemapping tool is used
to perform reverse (bottom-up) mappings of database tables to entity
source files. This is useful if developers want to generate Java files from a database for use in other
JPA applications. To run this tool:
- You need to have database tables and your database connection
configured.
newfeatRun the command
from the <profile_root> directory.
- The tool will generate .java files for every class along with
a XML descriptor file orm.xml
The generated Java files from the wsreversemapping
tool might require some editing before they can be used in an application.
Also, generated files will not contain annotations. Annotations can
be added manually if desired. Messages and errors are logged to the
console as specified by the configuration.
Examples
newfeat
Additional information
For more information,
consult the mapping section in the Apache OpenJPA User's Guide.