【问题标题】:How to get access to the Hibernate Statistics如何访问 Hibernate 统计信息
【发布时间】:2010-10-13 04:26:28
【问题描述】:

所以在我的persistence.xml 中,我打开了hibernate.generate_statistics

<property name="hibernate.generate_statistics">true</property>

我的问题是如何访问它们?统计数据到哪里去了?

【问题讨论】:

    标签: java hibernate jpa jboss jakarta-ee


    【解决方案1】:

    我宁愿使用 Hibernate Statistics published via JMX 如果你使用 spring 你可以使用 Hibernate Statistics MBean with Spring 让它变得非常容易

    【讨论】:

      【解决方案2】:

      在你的 dao 服务中你可以去:

      Session session = this.sessionFactory.getCurrentSession();
      SessionStatistics sessionStats = session.getStatistics();
      Statistics stats = this.sessionFactory.getStatistics(); 
      

      【讨论】:

        【解决方案3】:

        在我们的应用程序中,我们通过 JMX 发布它,为了使其完整,我们需要手动 add the criteria query data using aspects

        【讨论】:

          【解决方案4】:

          您还可以为其添加记录器。 看; http://www.thoughts-on-java.org/how-to-activate-hibernate-statistics-to-analyze-performance-issues/

          <!--Hibernate Statistics-->
                      <logger category="org.hibernate.stat" use-parent-handlers="true">
                          <level name="DEBUG"/>
                      </logger>
          

          【讨论】:

            【解决方案5】:

            您可以通过多种方式访问​​ Hibernate 统计信息:

            以编程方式

            如果你想在你的应用程序中获取Statistics对象,你可以这样做:

            Session session = entityManager.unwrap(Session.class);
            
            Statistics statistics = session.getSessionFactory().getStatistics();
            

            记录

            如果要记录Statistics报告,需要添加如下日志配置条目:

            <logger name="org.hibernate.engine.internal.StatisticalLoggingSessionEventListener" level="info"/>
            

            JMX

            您还可以通过设置hibernate.jmx.enabled 属性通过JMX 公开Statistics 对象。

            为此,您需要设置以下配置属性:

            <property name="hibernate.jmx.enabled" value="true"/>
            

            并在您的 JMX 客户端应用程序中找到 org.hibernate.core MBean 包。

            【讨论】:

              猜你喜欢
              • 2012-12-15
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 1970-01-01
              • 2011-02-24
              • 1970-01-01
              • 1970-01-01
              • 2012-07-22
              相关资源
              最近更新 更多