Announcement Announcement Module
Collapse
No announcement yet.
JPA and Hibernate statistics Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • JPA and Hibernate statistics

    Hello,

    I need to get the Hibernate statistics using JPA...I was checking the JMX bean StatisticsService which helps in collection of statictics...Unfortunately I do not have a handle on SessionFactory as I use EntityManager and PersistenceContext...I am using AbstractJPATests

    Does anyone have a solution for this ?


    Thanks...VJ

  • #2
    You should be able to cast EntityManagerFactory to HibernateEntityManagerFactory that has a getSessionFactory() method.

    Comment


    • #3
      Try something along these lines:

      Code:
      <?xml version="1.0" encoding="UTF-8"?>
      <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xmlns:aop="http://www.springframework.org/schema/aop" xmlns:util="http://www.springframework.org/schema/util"
          xmlns:jndi="http://www.springframework.org/schema/jndi" xmlns:tx="http://www.springframework.org/schema/tx"
          xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
                 http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.0.xsd
                 http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd
                 http://www.springframework.org/schema/jndi http://www.springframework.org/schema/jndi/spring-jndi-2.0.xsd
                 http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.0.xsd">
      
          <bean class="org.springframework.jmx.export.MBeanExporter">
              <property name="autodetect" value="false" />
              <property name="assembler">
                  <bean id="jmxAssembler" class="org.springframework.jmx.export.assembler.MetadataMBeanInfoAssembler">
                      <property name="attributeSource">
                          <bean class="org.springframework.jmx.export.annotation.AnnotationJmxAttributeSource"/>
                      </property>
                  </bean>
              </property>
              <property name="beans">
                  <map>
                      <entry key="org.hibernate:name=statistics">
                          <bean class="org.hibernate.jmx.StatisticsService">
                              <property name="statisticsEnabled" value="true" />
                              <property name="sessionFactory">
                                  <util:property-path path="entityManagerFactory.sessionFactory" />
                              </property>
                          </bean>
                      </entry>
                  </map>
              </property>
          </bean>
      
      </beans>

      Comment

      Working...
      X