使用JMX运行Hibernate 4.3(无弹簧) [英] running Hibernate 4.3 with JMX (without spring)

查看:104
本文介绍了使用JMX运行Hibernate 4.3(无弹簧)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Hibernate 4.3和Guice 1.0运行java webapp(wicket 6.13)

I'm running a java webapp (wicket 6.13) using Hibernate 4.3 and Guice 1.0

我正在尝试配置Hibernate,以便我可以通过Hibernate访问运行时信息JMX框架。

I'm trying to configure Hibernate so that I can access runtime information via the JMX framework.

我使用spring ,任何人都可以指示我如何在hibernate 4.3上手动启用JMX。

I'm not using spring, can anyone indicate how I enable the JMX on hibernate 4.3 manually.

我围绕JmxService,JmxServiceInitiator,JmxServiceImpl,StandardServiceRegistryImpl

I've poked around the JmxService, JmxServiceInitiator, JmxServiceImpl, StandardServiceRegistryImpl

我还在AvailableSettings中找到了以下设置:

I've also found the following settings in AvailableSettings:

"hibernate.jmx.enabled";
"hibernate.jmx.usePlatformServer";
"hibernate.jmx.agentId";
"hibernate.jmx.defaultDomain";
"hibernate.jmx.sessionFactoryName";

我已将jmx.enabled true设置添加到我的hibernate.cfg.xml文件中但这有没有效果。

I've added the jmx.enabled true setting to my hibernate.cfg.xml file but this has had no effect.

我仍然不确定如何解决这个问题。

I'm still not sure how to go about this.

任何帮助非常感谢

推荐答案

似乎是在重构hibernate后的一个bug。
请参阅 https://hibernate.atlassian.net/browse/HHH-6190 了解详情

seems to be a bug after refactoring in hibernate. see https://hibernate.atlassian.net/browse/HHH-6190 for details

这是我使用的一种解决方法,利用java动态代理来表示来自hibernate的统计接口,以及默认的平台mbean服务器:

Here's a workaround I've used, utilising a java dynamic proxy to represent the statistics interface from hibernate, and the default platform mbean server:

@MXBean
public interface StatisticsMXBean extends Statistics {
}

public void initStatistics(SessionFactory sessionFactory) {
    ObjectName statsName = new ObjectName("org.hibernate:type=statistics");
    MBeanServer mbeanServer = ManagementFactory.getPlatformMBeanServer();

    final Statistics statistics = sessionFactory.getStatistics();
    statistics.setStatisticsEnabled(true);
    Object statisticsMBean = Proxy.newProxyInstance(getClass().getClassLoader(), new Class<?>[] { StatisticsMXBean.class }, new InvocationHandler() {

            @Override
            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
                return method.invoke(statistics, args);
            }
        });

    mbeanServer.registerMBean(statisticsMBean, statsName);
}

这篇关于使用JMX运行Hibernate 4.3(无弹簧)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆