Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get access to the Hibernate Statistics

Tags:

So in my persistence.xml I turned on hibernate.generate_statistics.

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

My question is how do I access them? Where do the statistics go?

like image 476
mainstringargs Avatar asked Mar 13 '09 14:03

mainstringargs


People also ask

How can we get Hibernate statistics?

If you enable Hibernate statistics by setting the property hibernate. generate_statistics to true, Hibernate will expose a number of useful metrics. The page "Statistics" is used to expose these metrics.

How do you activate Hibernate statistics to analyze performance issues?

If you need to analyze performance issues, Hibernate can collect and log useful statistics about each database query and the whole session. This needs to be activated by setting the system property hibernate. generate_statistics to true and the log level for org.

How do I enable Hibernate logging?

The better way to activate the logging of executed SQL statements is to set the log level of the org. hibernate. SQL category to DEBUG (or the corresponding log level of your log framework).


2 Answers

In your dao service you can go:

Session session = this.sessionFactory.getCurrentSession(); SessionStatistics sessionStats = session.getStatistics(); Statistics stats = this.sessionFactory.getStatistics();  
like image 115
serg Avatar answered Dec 01 '22 19:12

serg


i would rather use Hibernate Statistics published via JMX if you use spring you can make it real easy with Hibernate Statistics MBean with Spring

like image 30
Michael Pralow Avatar answered Dec 01 '22 19:12

Michael Pralow