Reputation: 31
I have read this post. I cannot get whole objects as suggested in this post. I am getting MIN,MAX,Count values. So a new post. Below is what I want and what I have.
All my queries return scalar data. Not whole objects. (Ex: Select employee.name,office.address,MIN(employee.rec) from ... where..
)
I want my queries to be cached. So I enabled query cache in hibernate configuration.And added cacheable="true"
to my named queries.
4.I enabled second level cache.
5.Added the below annotation for the persistence class.
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
6. I want to refresh the cache every 24 hours. So updated timeToLiveSeconds
in ehcache.xml defaultCache
.
Is this the correct approach? How to know whether the query hits second level cache from query cache?
UPDATE: I added statistics and there was no hit/miss on second level cache.
Upvotes: 0
Views: 654
Reputation: 5692
Turn on SQL logging and statistics generation. If you see that SQL queries logging, that means cache doesn't work.
<property name="hibernate.show_sql" value="true"/>
<property name="hibernate.generate_statistics" value="true"/>
In order to see the hit count on second level cache:
session.getSessionFactory().getStatistics().getSecondLevelCacheHitCount()
Upvotes: 1