In Figure 23-10, you can see the information of each logged-in user, including the user name. This is
quite useful, for example, when an operator needs to check whether there are still users logging into the
application before performing any maintenance actions.
Monitoring Hibernate Statistics
Hibernate also supports the maintenance and exposure of persistence-related metrics to JMX. To enable
this, in the JPA configuration (the file /src/main/resources/datasource-tx-jpa.xml file), add two more
Hibernate properties, as shown in Listing 23-8.
Listing 23-8. Enable Hibernate Statistics
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
<!-- Other code omitted -->
<bean id="emf" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource" />
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" />
</property>
<property name="packagesToScan" value="com.apress.prospring3.ch23.domain"/>
<property name="jpaProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.H2Dialect</prop>
<prop key="hibernate.max_fetch_depth">3</prop>
<prop key="hibernate.jdbc.fetch_size">50</prop>
<prop key="hibernate.jdbc.batch_size">10</prop>
<prop key="hibernate.show_sql">true</prop>
<!-- Hibernate statistics properties -->
<prop key="hibernate.generate_statistics">true</prop>
<prop key="hibernate.session_factory_name">sessionFactory</prop>
</props>
</property>
</bean>
<!-- Other code omitted -->
</beans>
In Listing 23-8, the new properties are highlighted in bold. The property
hibernate.generate_statistics instructs Hibernate to generate statistics for its JPA persistence
provider, while the property hibernate.session_factory_name defines the name of the session factory
required by the Hibernate statistics MBean.
Finally, we need to add the MBean into Spring's MBeanExporter configuration. Listing 23-9 shows the
code snippet you need to add to the configuration file (src/main/resources/batch-context.xml).
Search WWH :
Custom Search
Previous Page
Spring Framework 3 Topic Index
Next Page
Spring Framework 3 Bookmarks
Home