How to set up Hibernate stats in a Spring 3.0 app?

How do we set it up so that we get Hibernate statistics via JMX in MVC web applications on Spring. Is there a better way to track Hibernate performance.

+6
source share
2 answers

Set hibernate.generate_statistics to true (either in persistence.xml , either in hibernate.cfg.xml or in your factory bean configuration). Then register this bean:

 <bean id="hibernateStatisticsMBean" class="org.hibernate.jmx.StatisticsService"> <property name="statisticsEnabled" value="true" /> <property name="sessionFactory" value="#{entityManagerFactory.sessionFactory}" /> </bean> 

(If you are not using JPA, just specify your sessionFactory bean instead of going through EMF)

And finally, you need a mbean server and exporter:

 <bean id="mbeanServer" class="org.springframework.jmx.support.MBeanServerFactoryBean"> <property name="locateExistingServerIfPossible" value="true" /> </bean> <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="server" ref="mbeanServer" /> <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING"/> <property name="beans"> <map> <entry key="yourkey:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" /> </map> </property> </bean> 
+8
source

Thank you for your submissions. I made two changes as follows.

  <bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter" lazy-init="false"> <property name="server" ref="mbeanServer" /> <property name="beans"> <map> <entry key="Qvantel:name=hibernateStatistics" value-ref="hibernateStatisticsMBean" /> </map> </property> <property name="registrationBehaviorName" value="REGISTRATION_REPLACE_EXISTING" /> </bean> 
0
source

Source: https://habr.com/ru/post/892840/


All Articles