3.6.2.3. Enhancing at Runtime
OpenJPA includes a Java agent for automatically enhancing persistent classes as they are loaded into the JVM.
Java agents are classes that are invoked prior to your application’s main method.
OpenJPA’s agent uses JVM hooks to intercept all class loading to enhance classes that have persistence metadata before the JVM loads them.
Searching for metadata for every class loaded by the JVM can slow application initialization. One way to speed things up is to take advantage of the optional persistent class list described in Persistent Class List. If you declare a persistent class list, OpenJPA will only search for metadata for classes in that list.
To employ the OpenJPA agent, invoke java with the
-javaagent set to the path to your OpenJPA jar file.
java -javaagent:/home/dev/openjpa/lib/openjpa.jar com.xyz.Main
You can pass settings to the agent using OpenJPA’s plugin syntax (see Plugin Configuration). The agent accepts the long form of any of the standard configuration options (Command Line Configuration ). It also accepts the following options, the first three of which correspond exactly to the same-named options of the enhancer tool described in Enhancing at Build Time:
-
addDefaultConstructor -
enforcePropertyRestrictions -
scanDevPath: Boolean indicating whether to scan the classpath for persistent types if none have been configured. If you do not specify a persistent types list and do not set this option to true, OpenJPA will check whether each class loaded into the JVM is persistent, and enhance it accordingly. This may slow down class load times significantly. -
classLoadEnhancement: Boolean controlling whether OpenJPA load-time class enhancement should be available in this JVM execution. Default:true -
runtimeRedefinition: Boolean controlling whether OpenJPA class redefinition should be available in this JVM execution. Default:true
java -javaagent:/home/dev/openjpa/lib/openjpa.jar=addDefaultConstructor=false com.xyz.Main