Apr 26 2009
Hibernate statistics on Tomcat with JMX
This little snippet will show you how to get Hibernate Statistics JMX MBean available.
Inside the tomcat startup script (bin/tomcatXw.exe), ensure that the following JAVA_OPTS are set:
JAVA_OPTS="
-Dcom.sun.management.jmxremote.port=9002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false
-Djava.awt.headless=true"
In your Spring config, add:
-
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"></bean>
-
-
<property name="beans">
-
<map>
-
<entry key="Hibernate:name=statistics">
-
<ref local="statisticsBean"/>
-
</entry>
-
</map>
-
</property>
-
<bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService"/>
-
<property name="statisticsEnabled"><value>true</value></property>
-
<property name="sessionFactory"><ref local="sessionFactory"></ref></property>
and then set the hibernate.generate_statistics property:
-
<prop key="hibernate.generate_statistics">true</prop>
When you browse the MBeans (using JConsole.exe - which lives in the bin dir of your JDK 1.5 distribution), you should see Hibernate, if you double click on that node, you should see the Statistics Bean.

