Collecting Hibernate/Ehcache statistics and exposing them through JMX in Spring-based setups seems easy. The Internet has lots of resources that help e.g.
http://snippets.dzone.com/posts/show/11159However, all those articles assume one is working with a Hibernate session factory of some sort. I'm not - my entities are JPA annotated and I use a javax.persistence.EntityManager. If I were deploying to a JEE container I might have been able to obtain a Hibernate session factory through JNDI as described here
http://internna.blogspot.com/2007/08/hibernate-statistics-in-enterprise-5.html but I'm on Tomcat...
How to go about this? I haven't come up with a solution yet.
If I had a reference to the Ehcache CacheManager I could try something like:
Code:
<context:mbean-server />
<bean class="net.sf.ehcache.management.ManagementService" init-method="init">
<constructor-arg ref="..myCacheManager.."/>
<constructor-arg ref="mbeanServer"/>
<constructor-arg value="true"/>
<constructor-arg value="true"/>
<constructor-arg value="true"/>
<constructor-arg value="true"/>
</bean>
Since the cache manager is created by Hibernate (i.e. it's not a Spring bean) it won't work. I tried replacing that ref with
Code:
<constructor-arg><bean id="cacheManager" class="net.sf.ehcache.CacheManager" factory-method="getInstance"/></constructor-arg>
hoping I'd somehow catch the right instance. Won't work either as this would in fact create a new cache manager instance.