NHibernate 1.2.0.2003
I'm trying to use second level cache for caching HQL queries in a web application. My query looks like this:
IList List<Child> = session.CreateQuery("from Child c where c.Parent.Id = :id order by c.Id ) .SetInt32("id",1) .SetCacheable(True) .SetCacheRegion("Main") .List<Child>();
Both Parent and Child have a <cache usage="read-write" /> in their xml files.
Following properties in the nHibernate configuration files (I am using the sessionfactory for multiple databases):
<property name="hibernate.prepare_sql">false</property> <property name="hibernate.cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property> <property name="hibernate.cache.use_query_cache">true</property> <property name="hibernate.use_reflection_optimizer">false</property> <property name="relativeExpiration">300</property>
When I look at the logging (and SQL server trace), I can see that second level cache is working for indiviual entities when they are loaded with the session.Load method.
The HQL query however, is always excuted (see select appearing in SQL Profiler).
In the logging of log4net, I always see the following log entry :cached query results were not up to date
Any idea what I'm doing wrong? What do I have to do to make this working?
|