Hi
If I understand well you want to make use 2-nd level cache for "Plan" objects. As far I know if you use query cache, and mark the query as cacheable, if you decide to return full objects, nhibernate will do two important things :
1) cache list of identifiers in the query cache
2) cache every entity returned by query in the 2-nd level cache
It is true for HQL queries, you can test it very well with log4net (priority="ALL"):
First run : (ceche is empty)
Code:
2008-01-19 20:08:57,110 [8] find: from interfejsLib.Kolumna k where k.User=:user and k.Grid=:grid
(...)
2008-01-19 20:08:57,111 [8] checking cached query results in region: NHibernate.Cache.StandardQueryCache
2008-01-19 20:08:57,111 [8] Fetching object 'NHibernate-Cache:NHibernate.Cache.StandardQueryCache:sql: select kolumna0_.Id as Id78_, kolumna0_.IdUser as IdUser78_, kolumna0_.IdProfil as IdProfil78_, kolumna0_.Grid as Grid78_, kolumna0_.Nazwa as Nazwa78_ from galKolumny kolumna0_ where (kolumna0_.IdUser=? )and(kolumna0_.Grid=? ); parameters: []; named parameters: {grid=webartykulylista_dgArtykuly, user=User#1}; first row: 0@49980227' from the cache.
2008-01-19 20:08:57,111 [8] query results were not found in cache
2008-01-19 20:08:57,111 [8] HQL: from interfejsLib.Kolumna k where k.User=:user and k.Grid=:grid
(...)
2008-01-19 20:08:57,112 [8] processing result set
(...)
2008-01-19 20:08:57,229 [8] adding entity to second-level cache [interfejsLib.Kolumna#16]
2008-01-19 20:08:57,229 [8] Caching: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#16
(...)
2008-01-19 20:08:57,230 [8] adding entity to second-level cache [interfejsLib.Kolumna#19]
2008-01-19 20:08:57,230 [8] Caching: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#19
(...)
2008-01-19 20:08:57,231 [8] caching query results in region: NHibernate.Cache.StandardQueryCache
2008-01-19 20:08:57,231 [8] adding new data: key=NHibernate-Cache:NHibernate.Cache.StandardQueryCache:sql: select kolumna0_.Id as Id78_, kolumna0_.IdUser as IdUser78_, kolumna0_.IdProfil as IdProfil78_, kolumna0_.Grid as Grid78_, kolumna0_.Nazwa as Nazwa78_ from galKolumny kolumna0_ where (kolumna0_.IdUser=? )and(kolumna0_.Grid=? ); parameters: []; named parameters: {grid=webartykulylista_dgArtykuly, user=User#1}; first row: 0@49980227&value=System.Collections.ArrayList
Second run : (cache is full - no database hit!)
Code:
2008-01-19 20:12:15,449 [8] find: from interfejsLib.Kolumna k where k.User=:user and k.Grid=:grid
(...)
2008-01-19 20:12:15,452 [8] checking cached query results in region: NHibernate.Cache.StandardQueryCache
(...)
2008-01-19 20:12:15,452 [8] returning cached query results
2008-01-19 20:12:15,452 [8] loading [Kolumna#16]
2008-01-19 20:12:15,452 [8] attempting to resolve [Kolumna#16]
2008-01-19 20:12:15,452 [8] Cache lookup: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#16
2008-01-19 20:12:15,452 [8] Fetching object 'NHibernate-Cache:interfejsLib.Kolumna:interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#16@16' from the cache.
2008-01-19 20:12:15,452 [8] Cache hit: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#16
2008-01-19 20:12:15,453 [8] resolved object in second-level cache [interfejsLib.Kolumna#16]
(...)
2008-01-19 20:12:15,453 [8] loading [Kolumna#19]
2008-01-19 20:12:15,453 [8] attempting to resolve [Kolumna#19]
2008-01-19 20:12:15,453 [8] Cache lookup: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#19
2008-01-19 20:12:15,453 [8] Fetching object 'NHibernate-Cache:interfejsLib.Kolumna:interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#19@19' from the cache.
2008-01-19 20:12:15,453 [8] Cache hit: interfejsLib.Kolumna, interfejsLib, Version=2.3.2940.35563, Culture=neutral, PublicKeyToken=null#19
2008-01-19 20:12:15,453 [8] resolved object in second-level cache [interfejsLib.Kolumna#19]
(...)
If it is true for ICriteria too (I suggest you to check it), best approach would be fetching full objects with query cache and 2-nd level cache enabled.