Hello,
I have following problem. It seems like HB Query cache stops working as soon as given object type is being saved (it does not matter if it was save to existing object or insert of new object instance).
The code looks like this:
// #1
query = session.createQuery("from User where userID = :id");
query.setCacheable(true);
query.setParameter("id", 10);
user = (User) query.list().get(0);
// #2
query = session.createQuery("from User where userID = :id");
query.setCacheable(true);
query.setParameter("id", 10);
user = (User) query.list().get(0);
// insert new User object
user = new User();
user.setUserID((int)(Math.random() * Integer.MAX_VALUE));
user.setUserName("Ten");
session.beginTransaction();
session.save(user);
session.getTransaction().commit();
// #3
query = session.createQuery("from User where userID = :id");
query.setCacheable(true);
query.setParameter("id", 10);
user = (User) query.list().get(0);
// #4
query = session.createQuery("from User where userID = :id");
query.setCacheable(true);
query.setParameter("id", 10);
user = (User) query.list().get(0);
From MS SQL Profiler I can clearly see that no queries is executed for #2 (e.g. it hit the cache), but queries are executed for #3 and #4. From HB debug log I see following:
For #2 Query (cache is hit) - correct:
06:54:25,337 DEBUG StandardQueryCache:102 - checking cached query results in region: org.hibernate.cache.StandardQueryCache
06:54:25,337 DEBUG StandardQueryCache:156 - Checking query spaces for up-to-dateness: [USERS]
06:54:25,337 DEBUG StandardQueryCache:117 - returning cached query results
During User insert:
06:54:25,368 DEBUG UpdateTimestampsCache:65 - Invalidating space [USERS], timestamp: 4967466866147328
For #3 Query:
06:54:25,368 DEBUG StandardQueryCache:156 - Checking query spaces for up-to-dateness: [USERS]
06:54:25,368 DEBUG UpdateTimestampsCache:86 - [USERS] last update timestamp: 4967466866147328, result set timestamp: 4967466865061888
06:54:25,368 DEBUG StandardQueryCache:113 - cached query results were not up to date
For #4 Query (or any subsequent query for this matter):
06:54:25,368 DEBUG StandardQueryCache:156 - Checking query spaces for up-to-dateness: [USERS]
06:54:25,368 DEBUG UpdateTimestampsCache:86 - [USERS] last update timestamp: 4967466866147328, result set timestamp: 4967466865061888
06:54:25,368 DEBUG StandardQueryCache:113 - cached query results were not up to date
Please note the timestamp numbers for #4 query - even though I would expect query to be re-cached in #3, it still shows old timestamp. So I may think that when re-caching a query it does not update cache entry timestamp which is not up-to-date due to save().
Is anyone could suggest if I need to post it as a bug?
Thanks,
Alex
|