Debugging JPA in WildFly

In order to debug the Persistence Service in WildFly you can increase the org.jboss.as.jpa logging in order to gather the following information:

  • INFO – will log information when persistence.xml has been parsed, when the persistence.xml has been deployed and when the persistence unit service has been stopped

  • DEBUG – will inform you when Entity Managers are injected, created or when reusing transaction scoped Entity Manager for active transaction

  • TRACE – shows how long each entity manager operation took in milliseconds, application searches for a persistence unit, parsing of persistence.xml

Example:

In order to enable TRACE, open the configuration file of the application sever and within the loggin subsystem add the org.jboss.as.jpa category. You also need to change the console-handler level from INFO to TRACE.

<subsystem xmlns="urn:jboss:domain:logging:1.0">
     <console-handler name="CONSOLE">
      <level name="TRACE" />
     ...
     </console-handler>

     </periodic-rotating-file-handler>
     <logger category="com.arjuna">
    <level name="WARN" />
  </logger>

     <logger category="org.jboss.as.jpa">
    <level name="TRACE" />
 </logger>

     <logger category="org.apache.tomcat.util.modeler">
    <level name="WARN" />
 </logger>
     ...

Besides it, to see what is going on at the JDBC level, within the datasource subsystem enable jboss.jdbc.spy TRACE as follows:

<datasource jndi-name="java:jboss/datasources/..." pool-name="..." enabled="true" spy="true">
<logger category="jboss.jdbc.spy">
 <level name="TRACE"/>
</logger>

Finally, to troubleshoot issues with the Hibernate second level cache, enable tracing for org.hibernate.SQL + org.hibernate.cache.infinispan
org.infinispan:

<subsystem xmlns="urn:jboss:domain:logging:1.0">
     <console-handler name="CONSOLE">
      <level name="TRACE" />
     ...
     </console-handler>

     </periodic-rotating-file-handler>
     <logger category="com.arjuna">
    <level name="WARN" />
  </logger>

     <logger category="org.hibernate.SQL">
    <level name="TRACE" />
 </logger>

     <logger category="org.hibernate">
    <level name="TRACE" />
 </logger>
     <logger category="org.infinispan">
    <level name="TRACE" />
 </logger>

     <logger category="org.apache.tomcat.util.modeler">
    <level name="WARN" />
 </logger>
     ...