3.6.2. Enhancement
In order to provide optimal runtime performance, flexible lazy loading, and efficient, immediate dirty tracking, OpenJPA can use an enhancer .
An enhancer is a tool that automatically adds code to your persistent classes after you have written them.
The enhancer post-processes the bytecode generated by your Java compiler, adding the necessary fields and methods to implement the required persistence features.
This bytecode modification perfectly preserves the line numbers in stack traces and is compatible with Java debuggers.
In fact, the only change to debugging is that the persistent setter and getter methods of entity classes using property access will be prefixed with pc in stack traces and step-throughs.
For example, if your entity has a getId method for persistent property id, and that method throws an exception, the stack trace will report the exception from method pcgetId.
The line numbers, however, will correctly correspond to the getId method in your source file.
The diagram above illustrates the compilation of a persistent class.
You can add the OpenJPA enhancer to your build process, or use Java 1.5’s instrumentation features to transparently enhance persistent classes when they are loaded into the JVM. The following sections describe each option.