Interface Statistics

All Known Subinterfaces:
StatisticsImplementor
All Known Implementing Classes:
StatisticsImpl

public interface Statistics
Exposes statistics collected from all sessions belonging to a given SessionFactory.

A custom statistics collector may be supplied by implementing the StatisticsImplementor SPI, and supplying a StatisticsFactory via the configuration setting "hibernate.stats.factory".

  • Field Details

  • Method Details

    • isStatisticsEnabled

      boolean isStatisticsEnabled()
      Is collection of statistics enabled?
    • setStatisticsEnabled

      void setStatisticsEnabled(boolean enabled)
      Enable or disable statistics collection.
    • clear

      void clear()
      Reset all statistics.
    • logSummary

      void logSummary()
      Log the main statistics at level INFO.
    • getEntityStatistics

      EntityStatistics getEntityStatistics(String entityName)
      Obtain the statistics for the entity with the given name.
      Parameters:
      entityName - the entity name
    • getCollectionStatistics

      CollectionStatistics getCollectionStatistics(String role)
      Obtain the statistics for the collection with the given role.
      Parameters:
      role - the collection role
    • getNaturalIdStatistics

      NaturalIdStatistics getNaturalIdStatistics(String entityName)
      Obtain the natural id resolution statistics for the entity type with the given name.
      Parameters:
      entityName - The entity name that is the root of the hierarchy containing the natural id
    • getQueryStatistics

      QueryStatistics getQueryStatistics(String queryString)
      Obtain the query statistics for the given query string.
      Parameters:
      queryString - the query string, written in HQL or SQL
    • getDomainDataRegionStatistics

      CacheRegionStatistics getDomainDataRegionStatistics(String regionName)
      Obtain the second-level cache statistics for the given cache region.
      Parameters:
      regionName - The unqualified region name
      Returns:
      the statistics for the named region, or null if the second-level cache is not enabled
      Throws:
      IllegalArgumentException - if there is no region with the given name
    • getQueryRegionStatistics

      @Nullable CacheRegionStatistics getQueryRegionStatistics(String regionName)
      Obtain the second-level cache statistics for the given query cache region.
      Parameters:
      regionName - The unqualified region name
      Returns:
      the statistics for the named region, or null if either query result caching is not enabled, or no query cache region exists with the given name
    • getCacheRegionStatistics

      @Nullable CacheRegionStatistics getCacheRegionStatistics(String regionName)
      Obtain the statistics for either a domain data or query result cache region.

      This method checks both, preferring the domain data region if there is one. Think of it as a cascading check to:

      1. getDomainDataRegionStatistics(java.lang.String)
      2. getQueryRegionStatistics(java.lang.String)
      Note that null is returned instead of throwing an exception when no region exists with the given name.
      Parameters:
      regionName - The unqualified region name
      Returns:
      the statistics for the named region, or null if there is no region with the given name
    • getEntityDeleteCount

      long getEntityDeleteCount()
      The global number of entity deletes.
    • getEntityInsertCount

      long getEntityInsertCount()
      The global number of entity inserts.
    • getEntityLoadCount

      long getEntityLoadCount()
      The global number of entity loads.
    • getEntityFetchCount

      long getEntityFetchCount()
      The global number of entity fetches.
    • getEntityUpdateCount

      long getEntityUpdateCount()
      The global number of entity updates.
    • getEntityUpsertCount

      long getEntityUpsertCount()
      The global number of entity upserts.
    • getQueryExecutionCount

      long getQueryExecutionCount()
      The global number of executed queries.
    • getQueryExecutionMaxTime

      long getQueryExecutionMaxTime()
      The time in milliseconds of the slowest query.
    • getQueryExecutionMaxTimeQueryString

      @Nullable String getQueryExecutionMaxTimeQueryString()
      The query string for the slowest query.
    • getQueryCacheHitCount

      long getQueryCacheHitCount()
      The global number of cached queries successfully retrieved from the cache.
    • getQueryCacheMissCount

      long getQueryCacheMissCount()
      The global number of cached queries notnot found in the cache.
    • getQueryCachePutCount

      long getQueryCachePutCount()
      The global number of cacheable queries put in cache.
    • getNaturalIdQueryExecutionCount

      long getNaturalIdQueryExecutionCount()
      The global number of natural id queries executed against the database.
    • getNaturalIdQueryExecutionMaxTime

      long getNaturalIdQueryExecutionMaxTime()
      The global maximum query time for natural id queries executed against the database.
    • getNaturalIdQueryExecutionMaxTimeRegion

      @Nullable String getNaturalIdQueryExecutionMaxTimeRegion()
      The region for the maximum natural id query time.
    • getNaturalIdQueryExecutionMaxTimeEntity

      @Nullable String getNaturalIdQueryExecutionMaxTimeEntity()
      The entity name for the maximum natural id query time.
    • getNaturalIdCacheHitCount

      long getNaturalIdCacheHitCount()
      The global number of cached natural id lookups successfully retrieved from the cache.
    • getNaturalIdCacheMissCount

      long getNaturalIdCacheMissCount()
      The global number of cached natural id lookups not found in the cache.
    • getNaturalIdCachePutCount

      long getNaturalIdCachePutCount()
      The global number of cacheable natural id lookups put in cache.
    • getUpdateTimestampsCacheHitCount

      long getUpdateTimestampsCacheHitCount()
      The global number of timestamps successfully retrieved from cache.
    • getUpdateTimestampsCacheMissCount

      long getUpdateTimestampsCacheMissCount()
      The global number of timestamp requests that were not found in the cache.
    • getUpdateTimestampsCachePutCount

      long getUpdateTimestampsCachePutCount()
      The global number of timestamps put in cache.
    • getFlushCount

      long getFlushCount()
      The global number of flush operations executed, including automatic (either manual or automatic).
    • getConnectCount

      long getConnectCount()
      The global number of connections requested by sessions.

      The actual number of connections used may be much smaller, assuming that a connection pool is in use.

    • getSecondLevelCacheHitCount

      long getSecondLevelCacheHitCount()
      The global number of cacheable entities and collections successfully retrieved from the cache.
    • getSecondLevelCacheMissCount

      long getSecondLevelCacheMissCount()
      The global number of cacheable entities collections not found in the cache and loaded from the database.
    • getSecondLevelCachePutCount

      long getSecondLevelCachePutCount()
      The global number of cacheable entities and collections put in the cache.
    • getSessionCloseCount

      long getSessionCloseCount()
      The global number of sessions closed.
    • getSessionOpenCount

      long getSessionOpenCount()
      The global number of sessions opened.
    • getCollectionLoadCount

      long getCollectionLoadCount()
      The global number of collections loaded.
    • getCollectionFetchCount

      long getCollectionFetchCount()
      The global number of collections fetched.
    • getCollectionUpdateCount

      long getCollectionUpdateCount()
      The global number of collections updated.
    • getCollectionRemoveCount

      long getCollectionRemoveCount()
      The global number of collections removed.
    • getCollectionRecreateCount

      long getCollectionRecreateCount()
      The global number of collections recreated
    • getStart

      Instant getStart()
      The Instant at which this instance of Statistics was created, or since the last time clear() was called.
    • getStartTime

      @Deprecated(since="6.0") long getStartTime()
      Deprecated.
      The Instant.toEpochMilli() milliseconds since the initial creation of this instance, or since the last time clear() was called.
    • getQueries

      String[] getQueries()
      All executed query strings.

      The maximum number of queries tracked by the Hibernate statistics is determined by the configuration property "hibernate.statistics.query_max_size".

      See Also:
    • getSlowQueries

      Map<String,Long> getSlowQueries()
      If "hibernate.log_slow_query" is enabled, a map from the SQL query to the maximum execution time in milliseconds.
      Since:
      6.3
      See Also:
    • getEntityNames

      String[] getEntityNames()
      The names of all entities.
    • getCollectionRoleNames

      String[] getCollectionRoleNames()
      The names of all collection roles.
    • getSecondLevelCacheRegionNames

      String[] getSecondLevelCacheRegionNames()
      All second-level cache region names. For backwards compatibility, this method returns just the names of regions storing domain data, not query result cache regions.
    • getSuccessfulTransactionCount

      long getSuccessfulTransactionCount()
      The number of transactions we know to have been successful.
    • getTransactionCount

      long getTransactionCount()
      The number of transactions we know to have completed.
    • getPrepareStatementCount

      long getPrepareStatementCount()
      The number of prepared statements that were acquired.
    • getCloseStatementCount

      long getCloseStatementCount()
      The number of prepared statements that were released.
    • getOptimisticFailureCount

      long getOptimisticFailureCount()
      The number of Hibernate StaleObjectStateExceptions or JPA OptimisticLockExceptions that have occurred.
    • getQueryPlanCacheHitCount

      long getQueryPlanCacheHitCount()
      The global number of query plans successfully retrieved from cache.
    • getQueryPlanCacheMissCount

      long getQueryPlanCacheMissCount()
      The global number of query plans lookups not found in cache.