我正在使用 Spring 3.1.1.RELEASE、JUnit 4.8.1 和 Hibernate 4.1.5.Final。我正在尝试测试我的二级缓存是否配置正确,但不确定如何操作。我正在使用 JPA 实体管理器,像这样在 Spring 中配置...
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="jpaDialect">
<bean class="org.collegeboard.springboard.core.jpa.HibernateJpaDialect">
<property name="flushMode" value="COMMIT"/>
</bean>
</property>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>
</property>
<property name="persistenceXmlLocation" value="classpath:META-INF/test-persistence.xml"/>
<property name="persistenceUnitName" value="orgTestingDatabase"/>
<property name="dataSource" ref="dataSource"/>
</bean>
<bean id="sharedEntityManager" class="org.springframework.orm.jpa.support.SharedEntityManagerBean">
<property name="entityManagerFactory" ref="entityManagerFactory"/>
</bean>
我已经像这样配置了我的二级缓存......
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">org.hibernate.cache.ehcache.EhCacheRegionFactory</property>
<property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property>
<!-- Collect stats, this is for testing if the cache is working -->
<property name="hibernate.generate_statistics">true</property>
给定我的 javax.persistence.EntityManager ,如何访问 org.hibernate.stat.Statistics 对象?显然,我需要以某种方式访问 SessionFactory,但我无法找出合适的演员阵容。
谢谢, - 戴夫