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 if you want 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 you might use this command frequently before packaging application files for testing. After you have created the JPA entities, you can run the wsenhancer tool to inject bytecode into the entities before packaging the Java archive (JAR) file into the enterprise archive (EAR) file for the application.
Syntax
The command syntax is as follows:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
wsenhancer.sh [parameters][arguments]
![[IBM i]](../images/iseries.gif)
wsenhancer [parameters][arguments]
![[Windows]](../images/windows.gif)
wsenhancer.bat [parameters][arguments]
Parameters
- -directory/-d <output directory>:
Specifies the path to the output directory.
If the directory does not match the enhanced class package, the package structure is created beneath the directory. By default, the enhancer overwrites the original .class file.
- -enforcePropertyRestrictions/-epr <true/t
| false/f>: Specifies whether to generate an exception
when a property access entity is not obeying the restrictions that
are placed on property access.
The default is set to false.
- -addDefaultConstructor/-adc <true/t | false/f>: Specifies that all of the persistent classes define a no-argument constructor. This flag informs the enhancer to add a protected no-arg constructor to any persistent classes in which the constructor is not already present.
- -tmpClassLoader/-tcl <true/t |
false/f>: Specifies whether the enhancer should load persistent
classes with a temporary class loader.
This function supports other code to load the enhanced version of the class afterward within the same Java virtual machine (JVM). The default is set to true.
Avoid trouble: If you are encountering class loading problems when running the enhancer, you can set this flag to false as a debugging step.gotcha
- For class name, specify one of the following:
- The full name of a class.
- The .java name for a class.
- The .class file of a class.
Usage
To use the wsenhancer tool you 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.
- Verify that your entities are in the class path, if they are not, add them.
- Run the wsenhancer command. It is found in profile_root/bin directory.
Examples
To enhance all entities on the class path:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer.sh
![[IBM i]](../images/iseries.gif)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer
![[Windows]](../images/windows.gif)
C:\myproject\cd build
C:\myproject\build>%profile_root%\bin\wsenhancer.bat
All entities in myproject are enhanced.
To enhance a specific entity when you have the source files:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer.sh Magazine.java
![[IBM i]](../images/iseries.gif)
$ cd build
/home/user/myproject/build $ ${profile_root}/bin/wsenhancer Magazine.java
![[Windows]](../images/windows.gif)
C:\myproject\cd build
C:\myproject\build>%profile_root%\bin\wsenhancer.bat Magazine.java
To enhance a specific entity when you have the compiled class files:
![[AIX]](../images/aixlogo.gif)
![[HP-UX]](../images/hpux.gif)
![[Linux]](../images/linux.gif)
![[Solaris]](../images/solaris.gif)
![[z/OS]](../images/ngzos.gif)
$ export CLASSPATH=target/classes
$ ${profile_root}/bin/wsenhancer.sh /bin/wsenhancer.sh target/classes/jpa/example/MyEntity.class
![[IBM i]](../images/iseries.gif)
$ export CLASSPATH=target/classes
$ ${profile_root}/bin/wsenhancer target/classes/jpa/example/MyEntity.class
![[Windows]](../images/windows.gif)
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.