Spring data JPA with Hibernate and Ehcache not working - Stack Overflow
Entity cache only works if the entity is retrieved using its id e.g. load(), get(). It doesn't work if you use query.
To enable caching the query you have to use Query cache. e.g.
List blogs = sess.createQuery("from Blog blog where blog.blogger = :blogger") .setEntity("blogger", blogger) .setMaxResults(15) .setCacheable(true) .setCacheRegion("frontpages") .list();
or using jpa
query.setHint("org.hibernate.cacheable", true);
I'm not sure how to implement this with QueryDslPredicateExecutor
, but hopes this will help to understand hibernate 2nd lvl cache
L2C hits and L2C misses are equal to zero means that hibernate never search the data from the cache because you are retrieving records using query without enabling the query cache
L2C puts not zero because hibernate cache the records to be used later if you retrieve the entity by its id(this is different than caching the query result)
Read full article from Spring data JPA with Hibernate and Ehcache not working - Stack Overflow
No comments:
Post a Comment