开发者

How to configure Hibernate statistics in Spring 3.0 application?

开发者 https://www.devze.com 2023-03-20 09:04 出处:网络
How do w开发者_Python百科e configure such that we obtain Hibernate statistics through JMX in Spring MVC based web applications. Is there any better way of tracking Hibernate performance.Set hibernate.

How do w开发者_Python百科e configure such that we obtain Hibernate statistics through JMX in Spring MVC based web applications. Is there any better way of tracking Hibernate performance.


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>


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>  
0

精彩评论

暂无评论...
验证码 换一张
取 消