The entity enhancer tool for Java Persistence API (JPA) applications in the application server inserts bytecode into an entity class file that allows the JPA provider to manage the state of an entity.
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 JAR file into the EAR file for the application.
Before running the command, you must have a copy of persistence.xml file on the classpath, or specify it as a properties file through the -p [path_to_persistence.xml] argument.
The command syntax is as follows:
wsenhancer.sh [parameters][arguments]
wsenhancer [parameters][arguments]
wsenhancer.bat [parameters][arguments]
In order to use the wsenhancer tool you need entities defined to JPA specifications, and the entities need to be compiled. Run the wsenhancer tool against the entities before packaging them into a JAR file. If the entities are already packaged, you must extract the entity class files, run the enhancer, and recreate the JAR file.
The command is run from the <WAS_HOME> directory.
To enhance your entities, verify that your entities are in the class path. If they are not, add them.
Messages and errors are logged to the console as specified in the log settings. After invoking the wsenhancer command, your files are enhanced.
$ cd build /home/user/myproject/build $ ${app_server_root}/bin/wsenhancer.sh
$ cd build /home/user/myproject/build $ ${app_server_root}/bin/wsenhancer
C:\myproject\cd build C:\myproject\build>%app_server_root%\bin\wsenhancer.batAll entities in myproject are be enhanced.
To enhance a specific entity when you have the source files:
$ cd build /home/user/myproject/build $ ${app_server_root}/bin/wsenhancer.sh Magazine.java
$ cd build /home/user/myproject/build $ ${app_server_root}/bin/wsenhancer Magazine.java
C:\myproject\cd build C:\myproject\build>%app_server_root%\bin\wsenhancer.bat Magazine.java
To enhance a specific entity when you have the compiled class files:
$ export CLASSPATH=target/classes $ ${app_server_root}/bin/wsenhancer.sh /bin/wsenhancer.sh target/classes/jpa/example/Magazine.class
$ export CLASSPATH=target/classes $ ${app_server_root}/bin/wsenhancer target/classes/jpa/example/Magazine.class
C:> cd build C:\build> SET CLASSPATH=target\classes C:\build>%app_server_root%\bin\wsenhancer.bat \bin\wsenhancer.bat target\classes\jpa\example\Magazine.class
The entity, Magazine.java, located in myproject are enhanced.
For more information about enhancement tools, refer to the section on persistent classes in the Apache OpenJPA reference documentation.