Hibernate 3.6.8.Final
Does anyone know how example criterias in hibernate work with the query cache. In my case, as soon as I enable caching on a criteria it stops working (never returns a result regardless of db contents).
Cache definitions
<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 config :
<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>
Query :-
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;
}
});
Like I said, if I remove setCacheable and the query region it works fine.
Cheers
Try to name your SessionFactory on your Hibernate configuration file. It seems there is a problem on later versions of Hibernate on handling cache replication via RMI (see at https://hibernate.onjira.com/browse/HHH-6162).