I'm struggling to configure hibernate jmx in order to have some metrics with the hibernate jconsole plugin.
actually I followed the configuration from the official website of hibernate jconsole plugin: http://hibernate-jcons.sourceforge.net/usage.html#pre-requisites
but it doesn't work so I searched on internet for hours, tested things. the only relevant thing I found, related to my problem, is that: How to configure Hibernate statistics in Spring 3.0 application?
But It still doesn't work. I need your help.
here is the configuration:
@PersistenceContext(unitName = DomainConstants.JPA_PU_BACKEND)
private EntityManager em;
@Bean(name="jmxExporter")
public MBeanExporter jmxExporter() throws MalformedObjectNameException, InstanceAlreadyExistsException, MBeanRegistrationException, NotCompliantMBeanException {
MBeanExporter exporter = new MBeanExporter();
Map<String, Object> beans = new HashMap<String, Object>();
beans.put("Hibernate:application=Statistics", "hibernateStatisticsBean");
MBeanServerFactoryBean serverFactory = new MBeanServerFactoryBean();
serverFactory.setLocateExistingServerIfPossible(true);
// --- new1
MBeanServer MBeanServer = serverFactory.getObject();
exporter.setServer(MBeanServer);
exporter.setRegistrationPolicy(RegistrationPolicy.REPLACE_EXISTING);
// end -- new1
exporter.setBeans(beans);
return exporter;
}
@Bean(name="hibernateStatisticsBean")
public StatisticsService hibernateStatisticsBean() {
StatisticsService service = new StatisticsService();
service.setStatisticsEnabled(true);
service.setSessionFactory(((Session)em.getDelegate()).getSessionFactory());
return service;
}
I also set hibernate.generate_statistics to true to the hibernate configuration.
I'm stuck. I really need this tool to work since we have queries that take a lot of time. this tool would be perfect.
EDIT: The MBean seems to be loaded. the attributes change when I do queries. image2 http://imageshack.com/a/img838/5904/dj8c.png
But when I tried to invoke one of the operations: getQueryStatistics, getCollectionStatistics etc.. I get the following error: image1 http://imageshack.com/a/img838/9693/ibkd.png
And actually I have no stats about the queries, nothing displayed: image3 http://imageshack.com/a/img835/8088/laoz.png