HibernateJMX with Spring

Hibernate Mbean is nice way to get runtime Hibernate Stat. Here is how to publish Hibernet Mbean to Tomcat Mbean server with Spring. Once Mbean are published, it can be access through Jconsole.

Tomcat setup:

 
JAVA_OPTS=" -Dcom.sun.management.jmxremote.port=9002  -Dcom.sun.management.jmxremote.authenticate=false  -Dcom.sun.management.jmxremote.ssl=false  -Djava.awt.headless=true" 


Spring config:

 
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter">
<property name="beans">
<map>
<entry key="Hibernate:name=statistics">
<ref local="statisticsBean">
</ref>
</entry></map>
</property>
</bean>

<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService">
<property name="statisticsEnabled">
<value>true</value>
</property>
<!-- Change this to match you own system if needed -->
<property name="sessionFactory"><ref local="sessionFactory"></ref>
</property>
</bean>


Hibernate property:
 
<prop key="hibernate.generate_statistics">true</prop>

Comments

Popular posts from this blog

Json to Avro

Parallel class hierarchies with Java Generic

Hibernate CacheMode.IGNORE option