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

Recommended Articles

Enhance Your Java Applications with Detailed SQL Logging and Formatting

Enable detailed SQL logging and formatting for better visibility of Hibernate operations. Learn how to configure persistence.xml and hibernate.cfg.xml files.

Enhance Your Enterprise Java Applications with Global JNDI Entity Manager Binding

Maximize your enterprise applications' performance and scalability by binding Persistence Units globally. Learn how to configure jboss.entity.manager.jndi.name and jboss.entity.manager.factory.jndi.name in persistence.xml for seamless integration.

Optimize Database Interactions with Hibernate Second Level Caches and Jakarta Persistence API

Learn how to configure Hibernate Second Level Caches for optimized database interactions, including monitoring with WildFly management tools.

Master JPA Entity Listeners: Enhance Your Java Persistence API with Callbacks

Learn how to leverage JPA Entity Listeners for customizing entity lifecycle events in WildFly 31 and beyond. #JPA #WildFly #JavaPersistenceAPI