+

Search Tips   |   Advanced Search

Enable Enhanced Tracing for Java Persistence API (JPA) in a Java SE environment


In some cases it may be necessary to run a JPA trace from a Java SE environment.

Enable enhanced tracing for a Java SE environment

Enhanced trace can also be used gather additional JPA trace information in a Java SE environment. In the WAS environment, the application server takes care of coupling the standard OpenJPA trace with the enhanced trace function to produce a single trace output. This must be done manually in a Java SE environment. Here are the steps to use enhanced tracing in a Java SE environment:

 

  1. Create a logging configuration properties file. This file must use the standard java.util.logging configuration file format. Below is a sample configuration file. The trace categories defined in the table below can also be used in the configuration file. As standard for java.util.logging configuration files, trace categories must be suffixed with .level.

    # Sample logger.properties file # Enable the file handler handlers = 
     java.util.logging.FileHandler # Set a trace file pattern - this pattern will write a file named # jpa_jse.log into the current 
     directory  java.util.logging.FileHandler.pattern = jpa_jse.log # Setup the basic logging level of the file handler 
     java.util.logging.FileHandler.level = ALL # Set the standard OpenJPA jdbc.SQL category to trace level to ALL 
     openjpa.jdbc.SQL.level = ALL # Set the enhanced OJPA_General category to trace at FINEST openjpa.OJPA_General.level = FINEST # 
    

    Set the enhanced OJPA_Kernel category to trace at FINER openjpa.OJPA_Kernel.level = FINER


    Table 1. Trace categories

    Category Relevant trace levels Description
    JPA OFF, ALL, FINER, FINEST Adds extended trace to the JPA trace group.
    openjpa.* OFF, ALL, FINER, FINEST Normal OpenJPA trace in addition to extended trace for all categories in OpenJPA when extended trace is enabled.
    openjpa.xtrace.* OFF, ALL, FINER, FINEST Extended trace for all categories in OpenJPA when extended trace is enabled.
    openjpa.xtrace.Jdbc OFF, ALL, FINER, FINEST Extended trace for OpenJPA JDBC classes when extended trace is enabled.
    openjpa.xtrace.Lib OFF, ALL, FINER, FINEST Extended trace for OpenJPA library classes when extended trace is enabled.
    openjpa.xtrace.Persist OFF, ALL, FINER, FINEST Extended trace for OpenJPA persistence classes when extended trace is enabled.
    openjpa.xtrace.Kernel OFF, ALL, FINER, FINEST Extended trace for OpenJPA kernel classes when extended trace is enabled.
    openjpa.xtrace.General OFF, ALL, FINER, FINEST Extended trace for OpenJPA classes not included in the JDBC, Lib, Persist, or Kernel categories when extended trace is enabled.

  2. Modify the persistence.xml file to use Apache commons logging instead of the default OpenJPA logger. Add this property to the persistence unit:

    <property name="openjpa.Log" value="commons"/>
    

  3. Add the apache commons logging JAR file to the class path. We can download the JAR file from the Apache Web site.

  4. Add the following argument to the JVM, where <WAS install path> is the fully qualified path of the appserver install directory. Be sure to use the path separator character appropriate for the operating system. This parameter must be specified before the name of the class or JAR file to be executed.

    -javaagent:<WAS install path>/optionalLibraries/IBM/wsjpa/wsjpatrace.jar
    

  5. Add this additional argument to the JVM which specifies the path to the logging configuration file. This option must also be specified before the name of the class or jar to be executed.

    -Djava.util.Logging.config.file=Logger.properties
    

  6. Run the Java SE application. Here is a sample Java SE application invocation with enhanced trace enabled:

    java -javaagent:"C:\Program 
    

    Files\IBM\WebSphere\AppServer\optionalLibraries\IBM\wsjpa\wsjpatrace.jar" -Djava.util.logging.config.file=logger.properties my.JPAApplication

 

Results

Enhanced tracing is now functioning in the Java SE environment.

 

Next steps

Use of extended trace agent should not be used in combination with the OpenJPA PCEnhancer agent in a Java SE environment. If enhanced tracing is used, the OpenJPA PCEnhancer must be used at compile time. If the enhancer and enhanced trace agents are used together the results are unpredictable.

 

Related tasks


Logging with the Java Persistence API (JPA) and the appserver