Enabling 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.

About this task

Enabling 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 WebSphere® Application Server 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:

Procedure

  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. Back up your server configuration before you enable enhanced tracing.
    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 your persistence.xml file to use Apache commons logging instead of the default OpenJPA logger. Add this property to your persistence unit:
    <property name="openjpa.Log" value="commons"/>
  3. Add the apache commons logging Java archive (JAR) file to your class path. You can download the JAR file from the Apache Web site.
  4. Add the following argument to the Java virtual machine (JVM), where <WAS install path> is the fully qualified path of your application server install directory. Be sure to use the path separator character appropriate for your 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 your 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 your 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 your Java SE environment.

What to do next

Note: 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.



In this information ...


IBM Redbooks, demos, education, and more

(Index)

Use IBM Suggests to retrieve related content from ibm.com and beyond, identified for your convenience.

This feature requires Internet access.

Task topic    

Terms of Use | Feedback

Last updated: Oct 21, 2010 1:44:59 AM CDT
http://www14.software.ibm.com/webapp/wsbroker/redirect?version=compass&product=was-express-dist&topic=tejb_jpatracejse
File name: tejb_jpatracejse.html