+

Search Tips   |   Advanced Search

wsenhancer command

The entity enhancer tool for Java Persistence API (JPA) applications inserts bytecode into an entity class file that supports the JPA provider to manage the state of an entity. Use this command-line tool to enhance entities under the Java Persistence API (JPA) 2.0 specification provider, WSJPA/OpenJPA, for WebSphere Application Server.

JPA with the application server requires that all entity classes be enhanced to manage their state. In a container-managed environment, automated enhancement is provided by the containers. In a Java SE environment, though, there are no containers to manage persistence and we might use this command frequently before packaging application files for testing. After we have created the JPA entities, we can run the wsenhancer tool to inject bytecode into the entities before packaging the JAR file into the EAR file for the application.


Syntax

Before running the command, we must have a copy of the persistence.xml file on the classpath, 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)

wsenhancer.sh [parameters][arguments]
(iSeries)
wsenhancer [parameters][arguments]
(Windows)
wsenhancer.bat [parameters][arguments]


Parameters

The enhancer accepts the standard set of command-line arguments defined by the configuration framework along with the following:

If we do not provide arguments to the enhancer, it runs on the classes in your persistent class list.

To use the wsenhancer tool we need entities defined to the JPA specifications, and the entities must be compiled. Run the wsenhancer tool against the entities before packaging them into a JAR file. If the entities are already packaged, you extract the entity class files, run the enhancer, and recreate the JAR file.

To enhance your entities:

Messages and errors are logged to the administrative console as specified in the log settings. After starting the wsenhancer command, the files are enhanced.


Examples

To enhance all entities on the class path:

(UNIX) (ZOS)

$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer.sh
(iSeries)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer
(Windows)
C:\myproject\cd build
C:\myproject\build>%profile_root%\bin\wsenhancer.bat 

All entities in myproject are enhanced.

To enhance a specific entity when we have the source files:

(UNIX) (ZOS)

$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer.sh Magazine.java
(iSeries)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer Magazine.java
(Windows)
C:\myproject\cd build
C:\myproject\build>%profile_root%\bin\wsenhancer.bat Magazine.java

To enhance a specific entity when we have the compiled class files:

(UNIX) (ZOS)

$ export CLASSPATH=target/classes
$ ${profile_root}/bin/wsenhancer.sh /bin/wsenhancer.sh target/classes/jpa/example/MyEntity.class
(iSeries)
$ export CLASSPATH=target/classes
$ ${profile_root}/bin/wsenhancer target/classes/jpa/example/MyEntity.class
(Windows)
C:> cd build
C:\build> SET CLASSPATH=target\classes
C:\build>%profile_root%\bin\wsenhancer.bat \bin\wsenhancer.bat target\classes\jpa\example\Magazine.class

The entity, Magazine.java, located in project are enhanced.


Additional information

For more information about enhancement tools, see the section on persistent classes in the Apache OpenJPA documentation.

  • 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