Hibernate version: 1.2.0beta3
Mapping documents:
In hibernate.cfg.xml:
Code:
<property name="cache.use_query_cache">false</property>
<property name="cache.provider_class">NHibernate.Caches.SysCache.SysCacheProvider, NHibernate.Caches.SysCache</property>
<property name="expiration">600</property>
In MyClass.hbm.xml:
Code:
<class name="MyEntity" table="my_entity" lazy="true" ...>
<cache usage="nonstrict-read-write" />
...
Name and version of the database you are using:SQL Server 2005
Debug level Hibernate log excerpt:Code:
2007-03-01 09:19:07,041 [11] DEBUG NHibernate.Caches.SysCache.SysCacheProvider - building cache with region: MyCompany.Entities.MyEntity, properties: blah blah blah ...
2007-03-01 09:19:07,057 [11] DEBUG NHibernate.Caches.SysCache.SysCache - new expiration value: 600
2007-03-01 09:19:07,057 [11] DEBUG NHibernate.Caches.SysCache.SysCache - no regionPrefix value given, using defaults
The SysCache appears to recognize that it should cache MyEntity, but if I repeatedly run the same HQL query within the expiration time, a trace through SQL Server Profiler shows that it gets all the rows from the my_entity table each time the HQL query is executed.
What am I doing wrong? Does the 2nd level cache only work when Get() or Load() is used? We rarely use them, we use HQL queries for most stuff. I did not enable the query cache because I read it only caches the IDs returned by the query, not the entity instances.
The behavior I wanted is that if a query is run multiple times within the expiration time, those entities already in the 2nd level cache are not re-selected, but any that aren't in the 2nd level cache do get selected. In other words, caching doesn't assume that the set of IDs returned by the query are the same as the last time the query was run, but it still only selects what it doesn't have cached. Usually it will be the case that the query result set has the same set of IDs, in which case nothing should be selected when the query is re-run. Is that possible?