Hibernate version: 1.2
I can't find anything that explains the relation between ICriteria queries and the session cache.
I've this small example below where I've expected only 1 SELECT statement sent to the database.
I am getting 2 SELECT statements (sql profitler) and that's my problem/question.
As you can see, the session "contains" the retrieved object but when the query is executed again, it look like it's not looking inside the session cache.
Code:
ISession session = SessionFactory.CurrentSession;
ICriteria criteria = session.CreateCriteria(typeof(Category));
//criteria.SetCacheable(true);
criteria.Add(new EqExpression("CategoryID", 1));
Category category = (Category)criteria.UniqueResult();
Assert.IsTrue(session.Contains(category));
// fetch it again .
Category category2 = (Category)criteria.UniqueResult();
Assert.AreEqual(category, category2);
Note: I've tried to use SetCacheable but i think that's something completelty different than the session cache and it's related to the query cache, which it's not this case.
Note2 : If i replace criteria.UniqueResult() with session.Load() , i get only 1 SELECT (which is what i want but still using ICriteria)
Is this expected behaviour?