Top Description Fields Methods
org.hibernate.stat

public Interface Statistics

Known Direct Subinterfaces
org.hibernate.stat.spi.StatisticsImplementor
Imports
java.time.Instant, java.util.Map, org.checkerframework.checker.nullness.qual.Nullable

Exposes statistics collected from all sessions belonging to a particular org.hibernate.SessionFactory.

Collection of statistics is enabled if the configuration property hibernate.generate_statistics is set to true. It may be dynamically enabled or disabled at runtime by calling setStatisticsEnabled(boolean).

Author
Emmanuel Bernard

Field Summary

Modifier and TypeField and Description
public static final int
DEFAULT_QUERY_STATISTICS_MAX_SIZE

The default value of the configuration property hibernate.statistics.query_max_size.

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Reset all statistics.

public @Nullable CacheRegionStatistics

Returns:

the statistics for the named region, or null if there is no region with the given name
getCacheRegionStatistics
(String
The unqualified region name
regionName
)

Obtain the statistics for either a domain data or query result cache region.

public long
getCloseStatementCount()

The number of prepared statements that were released.

public long
getCollectionFetchCount()

The global number of collections fetched.

public long
getCollectionLoadCount()

The global number of collections loaded.

public long
getCollectionRecreateCount()

The global number of collections recreated

public long
getCollectionRemoveCount()

The global number of collections removed.

public String[]
getCollectionRoleNames()

The names of all collection roles.

public CollectionStatistics
getCollectionStatistics(String
the collection role
role
)

Obtain the statistics for the collection with the given role.

public long
getCollectionUpdateCount()

The global number of collections updated.

public long
getConnectCount()

The global number of connections requested by sessions.

public CacheRegionStatistics

Returns:

the statistics for the named region, or null if the second-level cache is not enabled
getDomainDataRegionStatistics
(String
The unqualified region name
regionName
)

Obtain the second-level cache statistics for the given cache region.

public long
getEntityDeleteCount()

The global number of entity deletes.

public long
getEntityFetchCount()

The global number of entity fetches.

public long
getEntityInsertCount()

The global number of entity inserts.

public long
getEntityLoadCount()

The global number of entity loads.

public String[]
getEntityNames()

The names of all entities.

public EntityStatistics
getEntityStatistics(String
the entity name
entityName
)

Obtain the statistics for the entity with the given name.

public long
getEntityUpdateCount()

The global number of entity updates.

public long
getFlushCount()

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

public long
getNaturalIdCacheHitCount()

The global number of cached natural id lookups successfully retrieved from the cache.

public long
getNaturalIdCacheMissCount()

The global number of cached natural id lookups not found in the cache.

public long
getNaturalIdCachePutCount()

The global number of cacheable natural id lookups put in cache.

public long
getNaturalIdQueryExecutionCount()

The global number of natural id queries executed against the database.

public long
getNaturalIdQueryExecutionMaxTime()

The global maximum query time for natural id queries executed against the database.

public @Nullable String
getNaturalIdQueryExecutionMaxTimeEntity()

The entity name for the maximum natural id query time.

public @Nullable String
getNaturalIdQueryExecutionMaxTimeRegion()

The region for the maximum natural id query time.

public NaturalIdStatistics
getNaturalIdStatistics(String
The entity name that is the root of the hierarchy containing the natural id
entityName
)

Obtain the natural id resolution statistics for the entity type with the given name.

public long
getOptimisticFailureCount()

The number of Hibernate StaleObjectStateExceptions or JPA OptimisticLockExceptions that have occurred.

public long
getPrepareStatementCount()

The number of prepared statements that were acquired.

public String[]
getQueries()

All executed query strings.

public long
getQueryCacheHitCount()

The global number of cached queries successfully retrieved from the cache.

public long
getQueryCacheMissCount()

The global number of cached queries notnot found in the cache.

public long
getQueryCachePutCount()

The global number of cacheable queries put in cache.

public long
getQueryExecutionCount()

The global number of executed queries.

public long
getQueryExecutionMaxTime()

The time in milliseconds of the slowest query.

public @Nullable String
getQueryExecutionMaxTimeQueryString()

The query string for the slowest query.

public long
getQueryPlanCacheHitCount()

The global number of query plans successfully retrieved from cache.

public long
getQueryPlanCacheMissCount()

The global number of query plans lookups not found in cache.

public @Nullable CacheRegionStatistics

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
getQueryRegionStatistics
(String
The unqualified region name
regionName
)

Obtain the second-level cache statistics for the given query cache region.

public QueryStatistics
getQueryStatistics(String
the query string, written in HQL or SQL
queryString
)

Obtain the query statistics for the given query string.

public long
getSecondLevelCacheHitCount()

The global number of cacheable entities and collections successfully retrieved from the cache.

public long
getSecondLevelCacheMissCount()

The global number of cacheable entities collections not found in the cache and loaded from the database.

public long
getSecondLevelCachePutCount()

The global number of cacheable entities and collections put in the cache.

public String[]
getSecondLevelCacheRegionNames()

All second-level cache region names.

public long
getSessionCloseCount()

The global number of sessions closed.

public long
getSessionOpenCount()

The global number of sessions opened.

public Map<String, Long>
getSlowQueries()

If hibernate.log_slow_query is enabled, a map from the SQL query to the maximum execution time in milliseconds.

public Instant
getStart()

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

public long
getStartTime()

Deprecated since 6.0. use getStart()
The Instant#toEpochMilli() milliseconds since the initial creation of this instance, or since the last time clear() was called.
public long
getSuccessfulTransactionCount()

The number of transactions we know to have been successful.

public long
getTransactionCount()

The number of transactions we know to have completed.

public long
getUpdateTimestampsCacheHitCount()

The global number of timestamps successfully retrieved from cache.

public long
getUpdateTimestampsCacheMissCount()

The global number of timestamp requests that were not found in the cache.

public long
getUpdateTimestampsCachePutCount()

The global number of timestamps put in cache.

public boolean
isStatisticsEnabled()

Is collection of statistics enabled?

public void
logSummary()

Log the main statistics at level INFO.

public void
setStatisticsEnabled(boolean enabled)

Enable or disable statistics collection.

Field Detail

DEFAULT_QUERY_STATISTICS_MAX_SIZEback to summary
public static final int DEFAULT_QUERY_STATISTICS_MAX_SIZE

The default value of the configuration property hibernate.statistics.query_max_size.

Method Detail

clearback to summary
public void clear()

Reset all statistics.

getCacheRegionStatisticsback to summary
public @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
  2. getQueryRegionStatistics
Note that null is returned instead of throwing an exception when no region exists with the given name.
Parameters
regionName:String

The unqualified region name

Returns:@Nullable CacheRegionStatistics

the statistics for the named region, or null if there is no region with the given name

getCloseStatementCountback to summary
public long getCloseStatementCount()

The number of prepared statements that were released.

getCollectionFetchCountback to summary
public long getCollectionFetchCount()

The global number of collections fetched.

getCollectionLoadCountback to summary
public long getCollectionLoadCount()

The global number of collections loaded.

getCollectionRecreateCountback to summary
public long getCollectionRecreateCount()

The global number of collections recreated

getCollectionRemoveCountback to summary
public long getCollectionRemoveCount()

The global number of collections removed.

getCollectionRoleNamesback to summary
public String[] getCollectionRoleNames()

The names of all collection roles.

getCollectionStatisticsback to summary
public CollectionStatistics getCollectionStatistics(String role)

Obtain the statistics for the collection with the given role.

Parameters
role:String

the collection role

getCollectionUpdateCountback to summary
public long getCollectionUpdateCount()

The global number of collections updated.

getConnectCountback to summary
public 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.

getDomainDataRegionStatisticsback to summary
public CacheRegionStatistics getDomainDataRegionStatistics(String regionName)

Obtain the second-level cache statistics for the given cache region.

Parameters
regionName:String

The unqualified region name

Returns:CacheRegionStatistics

the statistics for the named region, or null if the second-level cache is not enabled

Exceptions
IllegalArgumentException:
if there is no region with the given name
getEntityDeleteCountback to summary
public long getEntityDeleteCount()

The global number of entity deletes.

getEntityFetchCountback to summary
public long getEntityFetchCount()

The global number of entity fetches.

getEntityInsertCountback to summary
public long getEntityInsertCount()

The global number of entity inserts.

getEntityLoadCountback to summary
public long getEntityLoadCount()

The global number of entity loads.

getEntityNamesback to summary
public String[] getEntityNames()

The names of all entities.

getEntityStatisticsback to summary
public EntityStatistics getEntityStatistics(String entityName)

Obtain the statistics for the entity with the given name.

Parameters
entityName:String

the entity name

getEntityUpdateCountback to summary
public long getEntityUpdateCount()

The global number of entity updates.

getFlushCountback to summary
public long getFlushCount()

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

getNaturalIdCacheHitCountback to summary
public long getNaturalIdCacheHitCount()

The global number of cached natural id lookups successfully retrieved from the cache.

getNaturalIdCacheMissCountback to summary
public long getNaturalIdCacheMissCount()

The global number of cached natural id lookups not found in the cache.

getNaturalIdCachePutCountback to summary
public long getNaturalIdCachePutCount()

The global number of cacheable natural id lookups put in cache.

getNaturalIdQueryExecutionCountback to summary
public long getNaturalIdQueryExecutionCount()

The global number of natural id queries executed against the database.

getNaturalIdQueryExecutionMaxTimeback to summary
public long getNaturalIdQueryExecutionMaxTime()

The global maximum query time for natural id queries executed against the database.

getNaturalIdQueryExecutionMaxTimeEntityback to summary
public @Nullable String getNaturalIdQueryExecutionMaxTimeEntity()

The entity name for the maximum natural id query time.

getNaturalIdQueryExecutionMaxTimeRegionback to summary
public @Nullable String getNaturalIdQueryExecutionMaxTimeRegion()

The region for the maximum natural id query time.

getNaturalIdStatisticsback to summary
public NaturalIdStatistics getNaturalIdStatistics(String entityName)

Obtain the natural id resolution statistics for the entity type with the given name.

Parameters
entityName:String

The entity name that is the root of the hierarchy containing the natural id

getOptimisticFailureCountback to summary
public long getOptimisticFailureCount()

The number of Hibernate StaleObjectStateExceptions or JPA OptimisticLockExceptions that have occurred.

getPrepareStatementCountback to summary
public long getPrepareStatementCount()

The number of prepared statements that were acquired.

getQueriesback to summary
public 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
org.hibernate.cfg.AvailableSettings#QUERY_STATISTICS_MAX_SIZE
getQueryCacheHitCountback to summary
public long getQueryCacheHitCount()

The global number of cached queries successfully retrieved from the cache.

getQueryCacheMissCountback to summary
public long getQueryCacheMissCount()

The global number of cached queries notnot found in the cache.

getQueryCachePutCountback to summary
public long getQueryCachePutCount()

The global number of cacheable queries put in cache.

getQueryExecutionCountback to summary
public long getQueryExecutionCount()

The global number of executed queries.

getQueryExecutionMaxTimeback to summary
public long getQueryExecutionMaxTime()

The time in milliseconds of the slowest query.

getQueryExecutionMaxTimeQueryStringback to summary
public @Nullable String getQueryExecutionMaxTimeQueryString()

The query string for the slowest query.

getQueryPlanCacheHitCountback to summary
public long getQueryPlanCacheHitCount()

The global number of query plans successfully retrieved from cache.

getQueryPlanCacheMissCountback to summary
public long getQueryPlanCacheMissCount()

The global number of query plans lookups not found in cache.

getQueryRegionStatisticsback to summary
public @Nullable CacheRegionStatistics getQueryRegionStatistics(String regionName)

Obtain the second-level cache statistics for the given query cache region.

Parameters
regionName:String

The unqualified region name

Returns:@Nullable CacheRegionStatistics

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

getQueryStatisticsback to summary
public QueryStatistics getQueryStatistics(String queryString)

Obtain the query statistics for the given query string.

Parameters
queryString:String

the query string, written in HQL or SQL

getSecondLevelCacheHitCountback to summary
public long getSecondLevelCacheHitCount()

The global number of cacheable entities and collections successfully retrieved from the cache.

getSecondLevelCacheMissCountback to summary
public long getSecondLevelCacheMissCount()

The global number of cacheable entities collections not found in the cache and loaded from the database.

getSecondLevelCachePutCountback to summary
public long getSecondLevelCachePutCount()

The global number of cacheable entities and collections put in the cache.

getSecondLevelCacheRegionNamesback to summary
public 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.

getSessionCloseCountback to summary
public long getSessionCloseCount()

The global number of sessions closed.

getSessionOpenCountback to summary
public long getSessionOpenCount()

The global number of sessions opened.

getSlowQueriesback to summary
public 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
org.hibernate.cfg.AvailableSettings#LOG_SLOW_QUERY
getStartback to summary
public Instant getStart()

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

getStartTimeback to summary
public long getStartTime()

Deprecated

since 6.0.

use getStart()

The Instant#toEpochMilli() milliseconds since the initial creation of this instance, or since the last time clear() was called.

Annotations
@Deprecated
since:6.0
getSuccessfulTransactionCountback to summary
public long getSuccessfulTransactionCount()

The number of transactions we know to have been successful.

getTransactionCountback to summary
public long getTransactionCount()

The number of transactions we know to have completed.

getUpdateTimestampsCacheHitCountback to summary
public long getUpdateTimestampsCacheHitCount()

The global number of timestamps successfully retrieved from cache.

getUpdateTimestampsCacheMissCountback to summary
public long getUpdateTimestampsCacheMissCount()

The global number of timestamp requests that were not found in the cache.

getUpdateTimestampsCachePutCountback to summary
public long getUpdateTimestampsCachePutCount()

The global number of timestamps put in cache.

isStatisticsEnabledback to summary
public boolean isStatisticsEnabled()

Is collection of statistics enabled?

logSummaryback to summary
public void logSummary()

Log the main statistics at level INFO.

setStatisticsEnabledback to summary
public void setStatisticsEnabled(boolean enabled)

Enable or disable statistics collection.