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?
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?
In your dao service you can go:
Session session = this.sessionFactory.getCurrentSession();
SessionStatistics sessionStats = session.getStatistics();
Statistics stats = this.sessionFactory.getStatistics();
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
There are multiple ways you can access the Hibernate Statistics:
If you want to get the Statistics
object in your application, you can do it as follows:
Session session = entityManager.unwrap(Session.class);
Statistics statistics = session.getSessionFactory().getStatistics();
If you want to log the Statistics
report, you need to add the following log configuration entry:
<logger name="org.hibernate.engine.internal.StatisticalLoggingSessionEventListener" level="info"/>
You can also expose the Statistics
object via JMX by setting the hibernate.jmx.enabled
property.
For this, you need to set the following configuration property:
<property name="hibernate.jmx.enabled" value="true"/>
And locate the org.hibernate.core
MBean package in your JMX client application.
You can also add a logger for it. See; http://www.thoughts-on-java.org/how-to-activate-hibernate-statistics-to-analyze-performance-issues/
<!--Hibernate Statistics-->
<logger category="org.hibernate.stat" use-parent-handlers="true">
<level name="DEBUG"/>
</logger>
In our application we published it via JMX and to make it complete we hat to kind of manually add the criteria query data using aspects