Managing Hibernate through MBeans
Two files need to be modified:
- src/main/resources/hibernate.cfg.xml where the following line should be added in the session-factory tag:
hibernate.cfg.xml
<property name="hibernate.generate_statistics">true</property>
- src/main/resources/applicationContext-dao.xml, just before the comment "If you want to be able to do simple CRUD...":
applicationContext-dao.xml
<bean id="jmxExporter" class="org.springframework.jmx.export.MBeanExporter"> <property name="beans"> <map> <entry key="Hibernate:name=statistics"> <ref local="statisticsBean" /> </entry> </map> </property> </bean> <bean id="statisticsBean" class="org.hibernate.jmx.StatisticsService"> <property name="statisticsEnabled"> <value>true</value> </property> <property name="sessionFactory" ref="sessionFactory" /> </bean>
Once the package recreated (mvn package or mvn jetty:run-war ) and the server restarted, a Hibernate entry appears among the other MBeans...
For Tomcat, the following options should be provided to the JVM (the port of course may be changed):
-Dcom.sun.management.jmxremote.port=9002 -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false