Discussion:
Hibernate JMX
Marian
2009-05-05 10:15:03 UTC
Permalink
If you can get it to work, we should probably
create a page in the 2.x wiki.
I've succeeded in a freshly new created project, by modifying the following two
files:

- src/main/resources/applicationContext-dao.xml
- src/main/resources/hibernate.cfg.xml

In the first file I've added (just before the comment " If you want to be able
to do simple CRUD...") the following :

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

In the second file, in the <session-factory> tag, just before the mappings I've
added:
<property name="hibernate.generate_statistics">true</property>

Then, once "mvn jetty:run-war" started the server, I could see with jconsole a
Hibernate MBean; please note that my project uses Java 6, but I presume that
nothing prevents Java 5 to expose the same behaviour.

For Tomcat, I had to add the options "-Dcom.sun.management.jmxremote.port=9002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false" - however, no
"-Djava.awt.headless=true" was required in order to have the Hibernate MBean.

Marian
Matt Raible
2009-05-05 14:59:46 UTC
Permalink
Thanks Marian!

It'd be awesome if you could put this information in AppFuse's
documentation. I'd suggest creating a child page under "Using Hibernate".

http://appfuse.org/display/APF/Using+Hibernate

Matt
Post by Marian
If you can get it to work, we should probably
create a page in the 2.x wiki.
I've succeeded in a freshly new created project, by modifying the following two
- src/main/resources/applicationContext-dao.xml
- src/main/resources/hibernate.cfg.xml
In the first file I've added (just before the comment " If you want to be able
================================================================
<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>
================================================================
In the second file, in the <session-factory> tag, just before the mappings I've
<property name="hibernate.generate_statistics">true</property>
Then, once "mvn jetty:run-war" started the server, I could see with jconsole a
Hibernate MBean; please note that my project uses Java 6, but I presume that
nothing prevents Java 5 to expose the same behaviour.
For Tomcat, I had to add the options
"-Dcom.sun.management.jmxremote.port=9002
-Dcom.sun.management.jmxremote.authenticate=false
-Dcom.sun.management.jmxremote.ssl=false" - however, no
"-Djava.awt.headless=true" was required in order to have the Hibernate MBean.
Marian
---------------------------------------------------------------------
haibin
2011-12-07 07:56:33 UTC
Permalink
It does not work for me. I did not see the Hibernate node in jconsole. Any
idea?

I'm using Appfuse 2.1.0 and Spring MVC.


<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
<property name="hibernateProperties">
<value>
hibernate.generate_statistics=true
hibernate.dialect=${hibernate.dialect}
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true

hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>


</property>
</bean>


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

--
View this message in context: http://appfuse.547863.n4.nabble.com/Hibernate-JMX-tp574863p4168082.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
Ebrahim Pasbani
2011-12-07 08:03:53 UTC
Permalink
Change

<entry key="Hibernate:name=
statistics">

to

<entry key="Hibernate:type=
statistics">
Post by haibin
It does not work for me. I did not see the Hibernate node in jconsole. Any
idea?
I'm using Appfuse 2.1.0 and Spring MVC.
<bean id="sessionFactory"
class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="configLocation"
value="classpath:hibernate.cfg.xml"/>
<property name="hibernateProperties">
<value>
hibernate.generate_statistics=true
hibernate.dialect=${hibernate.dialect}
hibernate.query.substitutions=true 'Y', false 'N'
hibernate.cache.use_second_level_cache=true
hibernate.cache.provider_class=org.hibernate.cache.EhCacheProvider
</value>
</property>
</bean>
<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>
--
http://appfuse.547863.n4.nabble.com/Hibernate-JMX-tp574863p4168082.html
Sent from the AppFuse - User mailing list archive at Nabble.com.
haibin
2011-12-07 08:26:24 UTC
Permalink
I tried "Hibernate:type=statistics" and it did not work either.

--
View this message in context: http://appfuse.547863.n4.nabble.com/Hibernate-JMX-tp574863p4168127.html
Sent from the AppFuse - User mailing list archive at Nabble.com.

Marian
2009-05-06 07:29:10 UTC
Permalink
Post by Matt Raible
It'd be awesome if you could put this information in AppFuse's
documentation. I'd suggest creating a child page under "Using Hibernate".
I'd love to...but how could I do that? AFAI could see, clicking on the
"Edit" button on the top of the page didn't show me any editable version
of it (shouldn't I be an administrator in order to do that?)

Regards

Marian
Matt Raible
2009-05-06 12:04:28 UTC
Permalink
You don't need to be an admin, you just need to be signed in. Here's the
link to create a new child page of the Hibernate tutorial.

http://appfuse.org/pages/createpage.action?spaceKey=APF&fromPageId=28

Matt
Post by Marian
Post by Matt Raible
It'd be awesome if you could put this information in AppFuse's
documentation. I'd suggest creating a child page under "Using Hibernate".
I'd love to...but how could I do that? AFAI could see, clicking on the
"Edit" button on the top of the page didn't show me any editable version
of it (shouldn't I be an administrator in order to do that?)
Regards
Marian
---------------------------------------------------------------------
Loading...