Package org.hibernate.stat
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
.
- Collection of statistics is enabled if the configuration property
"hibernate.generate_statistics"
is set to
true
. - Alternatively, statistics collection may be enabled or disabled
at runtime by calling
setStatisticsEnabled(boolean)
.
A custom statistics collector may be supplied by implementing the
StatisticsImplementor
SPI, and
supplying a StatisticsFactory
via
the configuration setting
"hibernate.stats.factory".
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final int
The default value of the configuration property "hibernate.statistics.query_max_size". -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
Reset all statistics.@Nullable CacheRegionStatistics
getCacheRegionStatistics
(String regionName) Obtain the statistics for either a domain data or query result cache region.long
The number of prepared statements that were released.long
The global number of collections fetched.long
The global number of collections loaded.long
The global number of collections recreatedlong
The global number of collections removed.String[]
The names of all collection roles.Obtain the statistics for the collection with the given role.long
The global number of collections updated.long
The global number of connections requested by sessions.getDomainDataRegionStatistics
(String regionName) Obtain the second-level cache statistics for the given cache region.long
The global number of entity deletes.long
The global number of entity fetches.long
The global number of entity inserts.long
The global number of entity loads.String[]
The names of all entities.getEntityStatistics
(String entityName) Obtain the statistics for the entity with the given name.long
The global number of entity updates.long
The global number of entity upserts.long
The global number of flush operations executed, including automatic (either manual or automatic).long
The global number of cached natural id lookups successfully retrieved from the cache.long
The global number of cached natural id lookups not found in the cache.long
The global number of cacheable natural id lookups put in cache.long
The global number of natural id queries executed against the database.long
The global maximum query time for natural id queries executed against the database.@Nullable String
The entity name for the maximum natural id query time.@Nullable String
The region for the maximum natural id query time.getNaturalIdStatistics
(String entityName) Obtain the natural id resolution statistics for the entity type with the given name.long
The number of HibernateStaleObjectStateException
s or JPAOptimisticLockException
s that have occurred.long
The number of prepared statements that were acquired.String[]
All executed query strings.long
The global number of cached queries successfully retrieved from the cache.long
The global number of cached queries notnot found in the cache.long
The global number of cacheable queries put in cache.long
The global number of executed queries.long
The time in milliseconds of the slowest query.@Nullable String
The query string for the slowest query.long
The global number of query plans successfully retrieved from cache.long
The global number of query plans lookups not found in cache.@Nullable CacheRegionStatistics
getQueryRegionStatistics
(String regionName) Obtain the second-level cache statistics for the given query cache region.getQueryStatistics
(String queryString) Obtain the query statistics for the given query string.long
The global number of cacheable entities and collections successfully retrieved from the cache.long
The global number of cacheable entities collections not found in the cache and loaded from the database.long
The global number of cacheable entities and collections put in the cache.String[]
All second-level cache region names.long
The global number of sessions closed.long
The global number of sessions opened.If "hibernate.log_slow_query" is enabled, a map from the SQL query to the maximum execution time in milliseconds.getStart()
long
Deprecated.long
The number of transactions we know to have been successful.long
The number of transactions we know to have completed.long
The global number of timestamps successfully retrieved from cache.long
The global number of timestamp requests that were not found in the cache.long
The global number of timestamps put in cache.boolean
Is collection of statistics enabled?void
Log the main statistics at levelINFO
.void
setStatisticsEnabled
(boolean enabled) Enable or disable statistics collection.
-
Field Details
-
DEFAULT_QUERY_STATISTICS_MAX_SIZE
static final int DEFAULT_QUERY_STATISTICS_MAX_SIZEThe default value of the configuration property "hibernate.statistics.query_max_size".- See Also:
-
-
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 levelINFO
. -
getEntityStatistics
Obtain the statistics for the entity with the given name.- Parameters:
entityName
- the entity name
-
getCollectionStatistics
Obtain the statistics for the collection with the given role.- Parameters:
role
- the collection role
-
getNaturalIdStatistics
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
Obtain the query statistics for the given query string.- Parameters:
queryString
- the query string, written in HQL or SQL
-
getDomainDataRegionStatistics
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
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
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:
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() -
getStartTime
Deprecated.usegetStart()
The Instant.toEpochMilli() milliseconds since the initial creation of this instance, or since the last timeclear()
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".
-
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 HibernateStaleObjectStateException
s or JPAOptimisticLockException
s 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.
-
getStart()