How to configure Hibernate statistics in Spring 3.0 application?

百般思念 提交于 2019-11-30 09:48:25

Set hibernate.generate_statistics to true (either in persistence.xml or in hibernate.cfg.xml or in your session 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 getting it through the EMF)

And finally you need an 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>
Hareesh Ram

Thanks Bozho for your inputs. I made two changes as specified below.

 <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>  
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!