Hi,
From the hibernate javadoc, I understand that setting the cacheable flag on a query controls whether or not the results are cached after the query is executed. "Hibernate in Action" views this differently - the cacheable flag is used to control both caching results after the query, and using the cache to get results during the query. However, running some tests I found that it only influences cache usage during query results retrieval. Specifically, I ran the following code
Session session = sessionFact.openSession();
Query q = session.createQuery(query);
q.setInteger("userId", user.getIx());
q.setCacheable(false);
twice by first setting the cacheable flag to true, then to false. In both cases I ran the query twice. Regardless of the value of the flag, results are cached after the query is executed. When the query was ran in cacheable mode, the second execution of the query doesn't go to the database, whereas in the other case, it does.
So my conclusion is that this flag only controls whether the cache is used for results retrieval, and has no influence on whether query results are cached after execution. Am I correct?
|