Network Deployment (Distributed operating systems), v8.0 > Reference > Command-line utilities
wsreversemapping command
The wsreversemapping tool generates persistent class definitions and metadata from a database schema.
Before running the command, have a copy of the persistence.xml file 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)
wsreversemapping.sh [parameters][arguments](Windows)wsreversemapping.bat [parameters][arguments]
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 wsreversmapping 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 are reverse mapped.
- -package/-p <package name>: The package name of the generated classes.
If no package name is given, the generated code does not contain package declarations.
- -directory/-d <output directory>: All generated code and metadata is written to the directory at this path.
If the path does not match the package of a class, the package structure is 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 and the table name in the name of each generated class.
This method 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 support 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.
Attention: 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 or one-to-one relations for every many-to-one or one-to-one relation detected.
- -useDatastoreIdentity/-ds <true/t | false/f>: Set to true to use data store identity for tables that have single numeric primary key columns.
Typically, the tool uses application identity for all generated classes.
- -useBuiltinIdentityClass/-bic <true/t | false/f>: Set this parameter flag to false to prevent the wsreversemapping tool from using built-in application identity classes when possible.
This forces 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 first looks for the CHAR(50,0) type name specification, then it looks for the CHAR(50), and finally 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.
Attention: Various databases report different type names differently, one database type might not work for another database. Enable TRACE level logging on the metadata channel to track which type names JPA for WAS is examining.
- -customizerClass/-cc <class name>: The full class name of an org.apache.openjpa.jdbc.meta.ReverseCustomizer customization plug-in.
If you do not specify a reverse customizer of your own, the system defaults to a PropertiesReverseCustomizer. This customizer supports specifying 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 is 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:
- We must have database tables and your database connection configured.
- Run the wsreversemapping tool from the command line in the $ {PROFILE_ROOT}/bin directory.
- The tool generates .java files for every class, along with an 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 do not contain annotations. Annotations can be added manually. Messages and errors are logged to the admin console as specified by the configuration.
Examples
Generate entities based on the information saved in the schema.xml file. Schema.xml was created by running the schema tool. The Java files are created in the src directory and use the package com.xyz:
(AIX) (Solaris)
${PROFILE_ROOT}/bin/wsreversemapping.sh -pkg com.xyz -d ./src schema.xml(Windows)${PROFILE_ROOT}\bin\wsreversemapping.bat -pkg com.xyz -d ./src schema.xmlGenerate entities based on information in a DB2 database. Entities are created in the src directory, and use the package com.reversemapped:
(AIX) (Solaris)
C:\> %PROFILE_ROOT%/bin/wsreversemapping.bat -sa dropDB Magazine.javapkg com.reversemapped -d src -connectionDriverName=com.ibm.db2.jcc.DB2Driver -connectionURL=jdbc:db2:localhost:50000/TEST -connectionUser=db2User -connectionPassword=db2Password(Windows)C:\> %PROFILE_ROOT%\bin\wsreversemapping.bat -sa dropDB Magazine.javapkg com.reversemapped -d src -connectionDriverName=com.ibm.db2.jcc.DB2Driver -connectionURL=jdbc:db2:localhost:50000/TEST -connectionUser=db2User -connectionPassword=db2Password
Additional information
For more information, read the mapping section in the Apache OpenJPA User Guide.
Develop JPA 2.x applications for a Java SE environment
Related