Hibernate / JPA and Infinispan statistics in EAP 6

Solution Verified - Updated -

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP) 6
  • Hibernate 4
  • Infinispan (as Level 2 Cache provider)

Issue

  • Enable Hibernate/JPA statistics
  • Enable Hibernate Infinispan statistics
  • Viewing statistics
  • Hibernate / Infinispan statistics are not visible in JConsole or JBoss Operations Network (JON)

Resolution

Enable Hibernate/JPA Statistics

  • In the persistence.xml add to the <persistent-unit>'s properties:1

    <property name="hibernate.generate_statistics" value="true"/>
    
  • For Native Hibernate, add to the hibernate.cfg.xml file the property:

    <property name="hibernate.generate_statistics">true</property>
    

Enable Infinispan Statistics2

  • In the persistence.xml add to the <persistent-unit>'s properties:

    <property name="hibernate.cache.infinispan.statistics" value="true"/>
    
    • Alternatively, to enable statistics for all persistence units, modify the hibernate cache container in the <standalone*|domain>.xml within the infinispan subsystem as follows:

      <cache-container name="hibernate" ... statistics-enabled="true">
      
  • For Native Hibernate, add to the hibernate.cfg.xml file the property:

    <property name="hibernate.cache.infinispan.statistics">true</property>
    
  • Once enabled, statistics for the Infinispan Cache Manager and all the managed caches (entity, collection, etc.) are enabled.3

View Statistics

  • JConsole
    • Hibernate / JPA statistics may be accessed from jboss.as / <deployment> / jpa / <deployment>#<persistence-unit>
    • Infinispan statistics may be accessed from jboss.infinispan / Cache / <deployment/cache name> / hibernate / Statistics / Attributes
  • JBoss CLI (<JBOSS_HOME>/bin/jboss-cli.sh)

    • Hibernate / JPA statistics may be displayed by running (substitute your own deployment archive and persistence unit name):

      /deployment=my-deployment.war/subsystem=jpa/hibernate-persistence-unit=my-deployment.war#my-persistence-unit/:read-resource(include-runtime=true)
      
    • Infinispan cache statistics are not exposed via CLI
  • EAP 6 Web Console
    • Some Hibernate JPA and Infinispan Statistics are available in by clicking View for an available persistence unit
      • Connections
      • Transactions
      • Queries
      • Second Level Cache

  1. In the EAP 6 Web Console, it is possible to temporarily enable/disable Hibernate/JPA statistics via the JPA / Persistence Units configuration page: edit the properties for the persistence unit, enable metrics and save. Note that this change will not persist across redeployment/restart of JBoss. 

  2. See also Configure Infinispan as Level 2 Cache 

  3. See also Using Infinispan as JPA-Hibernate Second Level Cache Provider -> Advanced Configuration

Root Cause

By default, Hibernate / JPA and Infinispan statistics are disabled. In previous JBoss Enterprise Application Platform (EAP) releases, statistics could be enabled via the org.hibernate.jmx.StatisticsService MBean. In EAP 6, this is no longer the case.

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments