Hibernate 3.6.8.Final
有谁知道hibernate中的示例标准如何与查询缓存一起工作。就我而言,只要我在条件上启用缓存就会停止工作(无论db内容如何都不会返回结果)。
缓存定义
<cache name="DimensionQueryCache"
maxElementsInMemory="100000"
eternal="true"
overflowToDisk="true" />
<cache name="org.hibernate.cache.StandardQueryCache"
maxElementsInMemory="100000"
eternal="false"
timeToIdleSeconds="3600"
timeToLiveSeconds="3600"
overflowToDisk="false" />
Hibernate配置:
<persistence-unit name="sqlServerPersistenceUnit" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
<properties>
<!-- See Hibernate's Environment class. -->
<property name="hibernate.dialect" value="org.hibernate.dialect.SQLServerDialect" />
<property name="hibernate.ejb.autodetection" value="class" />
<property name="hibernate.default_schema" value="dbo"/>
<property name="hibernate.max_fetch_depth" value="2" />
<property name="hibernate.show_sql" value="false" />
<property name="hibernate.format_sql" value="false" />
<property name="hibernate.use_sql_comments" value="false" />
<property name="hibernate.generate_statistics" value="false" />
<!-- If we ever switch to a clustered L2 cache, set hibernate.cache.use_structured_entries to true -->
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
<property name="hibernate.cache.use_structured_entries" value="false" />
<property name="net.sf.ehcache.configurationResourceName" value="META-INF/ehcache-hibernate.xml" />
<property name="hibernate.cache.provider_configuration_file_resource_path" value="META-INF/ehcache-hibernate.xml" />
<property name="hibernate.default_batch_fetch_size" value="16" />
<property name="hibernate.jdbc.batch_size" value="50" />
</properties>
</persistence-unit>
查询: -
Dimension existingCandidate= jpaTemplate.execute(new JpaCallback() {
public Object doInJpa(EntityManager em) throws PersistenceException {
Session session = (Session) em.getDelegate();
Dimension existingCandidate = (Dimension) session.createCriteria(dimension.getClass()).setCacheable(true).setCacheRegion("DimensionQueryCache").add(Example.create(dimension)).uniqueResult();
return existingCandidate;
}
});
就像我说的,如果删除setCacheable和查询区域,它可以正常工作。
干杯
答案 0 :(得分:0)
尝试在Hibernate配置文件中命名SessionFactory。在以后的Hibernate版本中,通过RMI处理缓存复制似乎存在问题(参见https://hibernate.onjira.com/browse/HHH-6162)。