Top Description Fields Constructors Methods
org.hibernate.jmx

public Class StatisticsService

extends Object
implements StatisticsServiceMBean
Class Inheritance
All Implemented Interfaces
org.hibernate.jmx.StatisticsServiceMBean, org.hibernate.stat.Statistics
Imports
javax.naming.InitialContext, .NameNotFoundException, .NamingException, .Reference, org.slf4j.Logger, .LoggerFactory, org.hibernate.SessionFactory, org.hibernate.impl.SessionFactoryObjectFactory, org.hibernate.stat.CollectionStatistics, .EntityStatistics, .QueryStatistics, .SecondLevelCacheStatistics, .Statistics, .StatisticsImpl

JMX service for Hibernate statistics

Register this MBean in your JMX server for a specific session factory
//build the ObjectName you want
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "myFinancialApp");
ObjectName on = new ObjectName("hibernate", tb);
StatisticsService stats = new StatisticsService();
stats.setSessionFactory(sessionFactory);
server.registerMBean(stats, on);
And call the MBean the way you want

Register this MBean in your JMX server with no specific session factory
//build the ObjectName you want
Hashtable tb = new Hashtable();
tb.put("type", "statistics");
tb.put("sessionFactory", "myFinancialApp");
ObjectName on = new ObjectName("hibernate", tb);
StatisticsService stats = new StatisticsService();
server.registerMBean(stats, on);
And call the MBean by providing the SessionFactoryJNDIName first. Then the session factory will be retrieved from JNDI and the statistics loaded.
Author
Emmanuel Bernard

Field Summary

Modifier and TypeField and Description
pack-priv Logger
pack-priv SessionFactory
pack-priv String
pack-priv Statistics

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
public void
clear()

Implements org.hibernate.stat.Statistics.clear.

reset all statistics
public long
getCloseStatementCount()

Implements org.hibernate.stat.Statistics.getCloseStatementCount.

The number of prepared statements that were released
public long
getCollectionFetchCount()

Implements org.hibernate.stat.Statistics.getCollectionFetchCount.

Global number of collections fetched
public long
getCollectionLoadCount()

Implements org.hibernate.stat.Statistics.getCollectionLoadCount.

Global number of collections loaded
public long
public long
getCollectionRemoveCount()

Implements org.hibernate.stat.Statistics.getCollectionRemoveCount.

Global number of collections removed
public String[]
getCollectionRoleNames()

Implements org.hibernate.stat.Statistics.getCollectionRoleNames.

Get the names of all collection roles
public CollectionStatistics
getCollectionStatistics(String
collection role
role
)

Implements org.hibernate.stat.Statistics.getCollectionStatistics.

Get collection statistics per role
public long
getCollectionUpdateCount()

Implements org.hibernate.stat.Statistics.getCollectionUpdateCount.

Global number of collections updated
public long
getConnectCount()

Implements org.hibernate.stat.Statistics.getConnectCount.

Get the global number of connections asked by the sessions (the actual number of connections used may be much smaller depending whether you use a connection pool or not)
public long
getEntityDeleteCount()

Implements org.hibernate.stat.Statistics.getEntityDeleteCount.

Get global number of entity deletes
public long
getEntityFetchCount()

Implements org.hibernate.stat.Statistics.getEntityFetchCount.

Get global number of entity fetchs
public long
getEntityInsertCount()

Implements org.hibernate.stat.Statistics.getEntityInsertCount.

Get global number of entity inserts
public long
getEntityLoadCount()

Implements org.hibernate.stat.Statistics.getEntityLoadCount.

Get global number of entity loads
public String[]
getEntityNames()

Implements org.hibernate.stat.Statistics.getEntityNames.

Get the names of all entities
public EntityStatistics
getEntityStatistics(String
entity name
entityName
)

Implements org.hibernate.stat.Statistics.getEntityStatistics.

find entity statistics per name
public long
getEntityUpdateCount()

Implements org.hibernate.stat.Statistics.getEntityUpdateCount.

Get global number of entity updates
public long
getFlushCount()

Implements org.hibernate.stat.Statistics.getFlushCount.

Get the global number of flush executed by sessions (either implicit or explicit)
public long
getOptimisticFailureCount()

Implements org.hibernate.stat.Statistics.getOptimisticFailureCount.

The number of StaleObjectStateExceptions that occurred
public long
getPrepareStatementCount()

Implements org.hibernate.stat.Statistics.getPrepareStatementCount.

The number of prepared statements that were acquired
public String[]
getQueries()

Implements org.hibernate.stat.Statistics.getQueries.

Get all executed query strings
public long
getQueryCacheHitCount()

Implements org.hibernate.stat.Statistics.getQueryCacheHitCount.

Get the global number of cached queries successfully retrieved from cache
public long
getQueryCacheMissCount()

Implements org.hibernate.stat.Statistics.getQueryCacheMissCount.

Get the global number of cached queries *not* found in cache
public long
getQueryCachePutCount()

Implements org.hibernate.stat.Statistics.getQueryCachePutCount.

Get the global number of cacheable queries put in cache
public long
getQueryExecutionCount()

Implements org.hibernate.stat.Statistics.getQueryExecutionCount.

Get global number of executed queries
public long
getQueryExecutionMaxTime()

Implements org.hibernate.stat.Statistics.getQueryExecutionMaxTime.

Get the time in milliseconds of the slowest query.
public String
public QueryStatistics
getQueryStatistics(String
query string
hql
)

Implements org.hibernate.stat.Statistics.getQueryStatistics.

Query statistics from query string (HQL or SQL)
public long
getSecondLevelCacheHitCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCacheHitCount.

Global number of cacheable entities/collections successfully retrieved from the cache
public long
getSecondLevelCacheMissCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCacheMissCount.

Global number of cacheable entities/collections not found in the cache and loaded from the database.
public long
getSecondLevelCachePutCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCachePutCount.

Global number of cacheable entities/collections put in the cache
public String[]
public SecondLevelCacheStatistics
getSecondLevelCacheStatistics(String
region name
regionName
)

Implements org.hibernate.stat.Statistics.getSecondLevelCacheStatistics.

Second level cache statistics per region
public long
getSessionCloseCount()

Implements org.hibernate.stat.Statistics.getSessionCloseCount.

Global number of sessions closed
public long
getSessionOpenCount()

Implements org.hibernate.stat.Statistics.getSessionOpenCount.

Global number of sessions opened
public long
public long
getSuccessfulTransactionCount()

Implements org.hibernate.stat.Statistics.getSuccessfulTransactionCount.

The number of transactions we know to have been successful
public long
getTransactionCount()

Implements org.hibernate.stat.Statistics.getTransactionCount.

The number of transactions we know to have completed
public boolean
public void
logSummary()

Implements org.hibernate.stat.Statistics.logSummary.

log in info level the main statistics
public void
setSessionFactory(SessionFactory
session factory to register
sf
)

Useful to init this MBean wo a JNDI session factory name

public void
setSessionFactoryJNDIName(String
session factory jndi name
sfJNDIName
)

Implements org.hibernate.jmx.StatisticsServiceMBean.setSessionFactoryJNDIName.

Publish the statistics of a session factory bound to the default JNDI context
public void
setStatisticsEnabled(boolean enable)

Implements org.hibernate.stat.Statistics.setStatisticsEnabled.

Enable statistics logs (this is a dynamic parameter)
Inherited from java.lang.Object:
cloneequalsfinalizegetClasshashCodenotifynotifyAlltoStringwaitwaitwait

Field Detail

logback to summary
pack-priv Logger log
sfback to summary
pack-priv SessionFactory sf
sfJNDINameback to summary
pack-priv String sfJNDIName
statsback to summary
pack-priv Statistics stats

Constructor Detail

StatisticsServiceback to summary
public StatisticsService()

Method Detail

clearback to summary
public void clear()

Implements org.hibernate.stat.Statistics.clear.

Doc from org.hibernate.stat.Statistics.clear.

reset all statistics

See Also
StatisticsServiceMBean#clear()
getCloseStatementCountback to summary
public long getCloseStatementCount()

Implements org.hibernate.stat.Statistics.getCloseStatementCount.

Doc from org.hibernate.stat.Statistics.getCloseStatementCount.

The number of prepared statements that were released

getCollectionFetchCountback to summary
public long getCollectionFetchCount()

Implements org.hibernate.stat.Statistics.getCollectionFetchCount.

Doc from org.hibernate.stat.Statistics.getCollectionFetchCount.

Global number of collections fetched

See Also
StatisticsServiceMBean#getCollectionFetchCount()
getCollectionLoadCountback to summary
public long getCollectionLoadCount()

Implements org.hibernate.stat.Statistics.getCollectionLoadCount.

Doc from org.hibernate.stat.Statistics.getCollectionLoadCount.

Global number of collections loaded

See Also
StatisticsServiceMBean#getCollectionLoadCount()
getCollectionRecreateCountback to summary
public long getCollectionRecreateCount()

Implements org.hibernate.stat.Statistics.getCollectionRecreateCount.

Doc from org.hibernate.stat.Statistics.getCollectionRecreateCount.

Global number of collections recreated

See Also
StatisticsServiceMBean#getCollectionRecreateCount()
getCollectionRemoveCountback to summary
public long getCollectionRemoveCount()

Implements org.hibernate.stat.Statistics.getCollectionRemoveCount.

Doc from org.hibernate.stat.Statistics.getCollectionRemoveCount.

Global number of collections removed

See Also
StatisticsServiceMBean#getCollectionRemoveCount()
getCollectionRoleNamesback to summary
public String[] getCollectionRoleNames()

Implements org.hibernate.stat.Statistics.getCollectionRoleNames.

Doc from org.hibernate.stat.Statistics.getCollectionRoleNames.

Get the names of all collection roles

getCollectionStatisticsback to summary
public CollectionStatistics getCollectionStatistics(String role)

Implements org.hibernate.stat.Statistics.getCollectionStatistics.

Doc from org.hibernate.stat.Statistics.getCollectionStatistics.

Get collection statistics per role

Parameters
role:String

collection role

Returns:CollectionStatistics

CollectionStatistics

See Also
StatisticsServiceMBean#getCollectionStatistics(java.lang.String)
getCollectionUpdateCountback to summary
public long getCollectionUpdateCount()

Implements org.hibernate.stat.Statistics.getCollectionUpdateCount.

Doc from org.hibernate.stat.Statistics.getCollectionUpdateCount.

Global number of collections updated

See Also
StatisticsServiceMBean#getCollectionUpdateCount()
getConnectCountback to summary
public long getConnectCount()

Implements org.hibernate.stat.Statistics.getConnectCount.

Doc from org.hibernate.stat.Statistics.getConnectCount.

Get the global number of connections asked by the sessions (the actual number of connections used may be much smaller depending whether you use a connection pool or not)

See Also
StatisticsServiceMBean#getConnectCount()
getEntityDeleteCountback to summary
public long getEntityDeleteCount()

Implements org.hibernate.stat.Statistics.getEntityDeleteCount.

Doc from org.hibernate.stat.Statistics.getEntityDeleteCount.

Get global number of entity deletes

Returns:long

entity deletion count

See Also
StatisticsServiceMBean#getEntityDeleteCount()
getEntityFetchCountback to summary
public long getEntityFetchCount()

Implements org.hibernate.stat.Statistics.getEntityFetchCount.

Doc from org.hibernate.stat.Statistics.getEntityFetchCount.

Get global number of entity fetchs

Returns:long

entity fetch (from DB)

See Also
StatisticsServiceMBean#getEntityFetchCount()
getEntityInsertCountback to summary
public long getEntityInsertCount()

Implements org.hibernate.stat.Statistics.getEntityInsertCount.

Doc from org.hibernate.stat.Statistics.getEntityInsertCount.

Get global number of entity inserts

Returns:long

entity insertion count

See Also
StatisticsServiceMBean#getEntityInsertCount()
getEntityLoadCountback to summary
public long getEntityLoadCount()

Implements org.hibernate.stat.Statistics.getEntityLoadCount.

Doc from org.hibernate.stat.Statistics.getEntityLoadCount.

Get global number of entity loads

Returns:long

entity load (from DB)

See Also
StatisticsServiceMBean#getEntityLoadCount()
getEntityNamesback to summary
public String[] getEntityNames()

Implements org.hibernate.stat.Statistics.getEntityNames.

Doc from org.hibernate.stat.Statistics.getEntityNames.

Get the names of all entities

getEntityStatisticsback to summary
public EntityStatistics getEntityStatistics(String entityName)

Implements org.hibernate.stat.Statistics.getEntityStatistics.

Doc from org.hibernate.stat.Statistics.getEntityStatistics.

find entity statistics per name

Parameters
entityName:String

entity name

Returns:EntityStatistics

EntityStatistics object

See Also
StatisticsServiceMBean#getEntityStatistics(java.lang.String)
getEntityUpdateCountback to summary
public long getEntityUpdateCount()

Implements org.hibernate.stat.Statistics.getEntityUpdateCount.

Doc from org.hibernate.stat.Statistics.getEntityUpdateCount.

Get global number of entity updates

Returns:long

entity update

See Also
StatisticsServiceMBean#getEntityUpdateCount()
getFlushCountback to summary
public long getFlushCount()

Implements org.hibernate.stat.Statistics.getFlushCount.

Doc from org.hibernate.stat.Statistics.getFlushCount.

Get the global number of flush executed by sessions (either implicit or explicit)

See Also
StatisticsServiceMBean#getFlushCount()
getOptimisticFailureCountback to summary
public long getOptimisticFailureCount()

Implements org.hibernate.stat.Statistics.getOptimisticFailureCount.

Doc from org.hibernate.stat.Statistics.getOptimisticFailureCount.

The number of StaleObjectStateExceptions that occurred

getPrepareStatementCountback to summary
public long getPrepareStatementCount()

Implements org.hibernate.stat.Statistics.getPrepareStatementCount.

Doc from org.hibernate.stat.Statistics.getPrepareStatementCount.

The number of prepared statements that were acquired

getQueriesback to summary
public String[] getQueries()

Implements org.hibernate.stat.Statistics.getQueries.

Doc from org.hibernate.stat.Statistics.getQueries.

Get all executed query strings

getQueryCacheHitCountback to summary
public long getQueryCacheHitCount()

Implements org.hibernate.stat.Statistics.getQueryCacheHitCount.

Doc from org.hibernate.stat.Statistics.getQueryCacheHitCount.

Get the global number of cached queries successfully retrieved from cache

getQueryCacheMissCountback to summary
public long getQueryCacheMissCount()

Implements org.hibernate.stat.Statistics.getQueryCacheMissCount.

Doc from org.hibernate.stat.Statistics.getQueryCacheMissCount.

Get the global number of cached queries *not* found in cache

getQueryCachePutCountback to summary
public long getQueryCachePutCount()

Implements org.hibernate.stat.Statistics.getQueryCachePutCount.

Doc from org.hibernate.stat.Statistics.getQueryCachePutCount.

Get the global number of cacheable queries put in cache

getQueryExecutionCountback to summary
public long getQueryExecutionCount()

Implements org.hibernate.stat.Statistics.getQueryExecutionCount.

Doc from org.hibernate.stat.Statistics.getQueryExecutionCount.

Get global number of executed queries

Returns:long

query execution count

See Also
StatisticsServiceMBean#getQueryExecutionCount()
getQueryExecutionMaxTimeback to summary
public long getQueryExecutionMaxTime()

Implements org.hibernate.stat.Statistics.getQueryExecutionMaxTime.

Doc from org.hibernate.stat.Statistics.getQueryExecutionMaxTime.

Get the time in milliseconds of the slowest query.

getQueryExecutionMaxTimeQueryStringback to summary
public String getQueryExecutionMaxTimeQueryString()

Implements org.hibernate.stat.Statistics.getQueryExecutionMaxTimeQueryString.

Doc from org.hibernate.stat.Statistics.getQueryExecutionMaxTimeQueryString.

Get the query string for the slowest query.

getQueryStatisticsback to summary
public QueryStatistics getQueryStatistics(String hql)

Implements org.hibernate.stat.Statistics.getQueryStatistics.

Doc from org.hibernate.stat.Statistics.getQueryStatistics.

Query statistics from query string (HQL or SQL)

Parameters
hql:String

query string

Returns:QueryStatistics

QueryStatistics

See Also
StatisticsServiceMBean#getQueryStatistics(java.lang.String)
getSecondLevelCacheHitCountback to summary
public long getSecondLevelCacheHitCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCacheHitCount.

Doc from org.hibernate.stat.Statistics.getSecondLevelCacheHitCount.

Global number of cacheable entities/collections successfully retrieved from the cache

See Also
StatisticsServiceMBean#getSecondLevelCacheHitCount()
getSecondLevelCacheMissCountback to summary
public long getSecondLevelCacheMissCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCacheMissCount.

Doc from org.hibernate.stat.Statistics.getSecondLevelCacheMissCount.

Global number of cacheable entities/collections not found in the cache and loaded from the database.

See Also
StatisticsServiceMBean#getSecondLevelCacheMissCount()
getSecondLevelCachePutCountback to summary
public long getSecondLevelCachePutCount()

Implements org.hibernate.stat.Statistics.getSecondLevelCachePutCount.

Doc from org.hibernate.stat.Statistics.getSecondLevelCachePutCount.

Global number of cacheable entities/collections put in the cache

See Also
StatisticsServiceMBean#getSecondLevelCachePutCount()
getSecondLevelCacheRegionNamesback to summary
public String[] getSecondLevelCacheRegionNames()

Implements org.hibernate.stat.Statistics.getSecondLevelCacheRegionNames.

Doc from org.hibernate.stat.Statistics.getSecondLevelCacheRegionNames.

Get all second-level cache region names

getSecondLevelCacheStatisticsback to summary
public SecondLevelCacheStatistics getSecondLevelCacheStatistics(String regionName)

Implements org.hibernate.stat.Statistics.getSecondLevelCacheStatistics.

Doc from org.hibernate.stat.Statistics.getSecondLevelCacheStatistics.

Second level cache statistics per region

Parameters
regionName:String

region name

Returns:SecondLevelCacheStatistics

SecondLevelCacheStatistics

See Also
StatisticsServiceMBean#getSecondLevelCacheStatistics(java.lang.String)
getSessionCloseCountback to summary
public long getSessionCloseCount()

Implements org.hibernate.stat.Statistics.getSessionCloseCount.

Doc from org.hibernate.stat.Statistics.getSessionCloseCount.

Global number of sessions closed

See Also
StatisticsServiceMBean#getSessionCloseCount()
getSessionOpenCountback to summary
public long getSessionOpenCount()

Implements org.hibernate.stat.Statistics.getSessionOpenCount.

Doc from org.hibernate.stat.Statistics.getSessionOpenCount.

Global number of sessions opened

See Also
StatisticsServiceMBean#getSessionOpenCount()
getStartTimeback to summary
public long getStartTime()

Implements org.hibernate.stat.Statistics.getStartTime.

Returns:long

Doc from org.hibernate.stat.Statistics.getStartTime.

start time in ms (JVM standards System#currentTimeMillis())

See Also
StatisticsServiceMBean#getStartTime()
getSuccessfulTransactionCountback to summary
public long getSuccessfulTransactionCount()

Implements org.hibernate.stat.Statistics.getSuccessfulTransactionCount.

Doc from org.hibernate.stat.Statistics.getSuccessfulTransactionCount.

The number of transactions we know to have been successful

getTransactionCountback to summary
public long getTransactionCount()

Implements org.hibernate.stat.Statistics.getTransactionCount.

Doc from org.hibernate.stat.Statistics.getTransactionCount.

The number of transactions we know to have completed

isStatisticsEnabledback to summary
public boolean isStatisticsEnabled()

Implements org.hibernate.stat.Statistics.isStatisticsEnabled.

Doc from org.hibernate.stat.Statistics.isStatisticsEnabled.

Are statistics logged

See Also
StatisticsServiceMBean#isStatisticsEnabled()
logSummaryback to summary
public void logSummary()

Implements org.hibernate.stat.Statistics.logSummary.

Doc from org.hibernate.stat.Statistics.logSummary.

log in info level the main statistics

setSessionFactoryback to summary
public void setSessionFactory(SessionFactory sf)

Useful to init this MBean wo a JNDI session factory name

Parameters
sf:SessionFactory

session factory to register

setSessionFactoryJNDINameback to summary
public void setSessionFactoryJNDIName(String sfJNDIName)

Implements org.hibernate.jmx.StatisticsServiceMBean.setSessionFactoryJNDIName.

Doc from org.hibernate.jmx.StatisticsServiceMBean.setSessionFactoryJNDIName.

Publish the statistics of a session factory bound to the default JNDI context

Parameters
sfJNDIName:String

session factory jndi name

See Also
StatisticsServiceMBean#setSessionFactoryJNDIName(java.lang.String)
setStatisticsEnabledback to summary
public void setStatisticsEnabled(boolean enable)

Implements org.hibernate.stat.Statistics.setStatisticsEnabled.

Doc from org.hibernate.stat.Statistics.setStatisticsEnabled.

Enable statistics logs (this is a dynamic parameter)

See Also
StatisticsServiceMBean#setStatisticsEnabled(boolean)