Access Keys:
Skip to content (Access Key - 0)

Managing Hibernate through MBeans

Labels

hibernate hibernate Delete
jmx jmx Delete
Enter labels to add to this page:
Please wait 
Looking for a label? Just start typing.

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
Adaptavist Theme Builder (4.0.0-M8) Powered by Atlassian Confluence 3.1, the Enterprise Wiki.