Hibernate version: 3.0.5
Hi all,
I'm running into a query cache issue using a Criteria object with the
criterion, Restrictions.idEq(). The Criteria is created as follows:
User user = (User) session.createCriteria(User.class)
.add(Restrictions.idEq(1))
.setFetchMode("groups", fetchMode)
.setCacheable(true)
.setCacheMode(CacheMode.NORMAL)
.uniqueResult();
I am using a Criteria rather than Session.load() or Session.get() so
that the fetch mode can be set dynamically.
I can see from the logs that the query and result set are cached in
StandardQueryCache. The result set is properly returned from the cache
until the timestamp for User is updated in UpdateTimestampsCache when
a User entity is created, updated, or deleted. At this point, the
timestamp for the result set in StandardQueryCache precedes the
timestamp in UpdateTimestampsCache, making the result set out-of-date.
The result set is obtained from the database and is then re-cached
with the query and updated timestamp in StandardQueryCache.
I noticed there is an optimization where querying by natural ID can
avoid this cache invalidation, but there doesn't seem to be one for
querying by the actual id. Am I missing something? Is there a reason
not to do this?
Thanks for your help!
|