-
1. Re: JPA query cache
smarlow Feb 6, 2014 11:25 AM (in response to whelan)1 of 1 people found this helpfulFrom the Hibernate documentation:
So by default, individual queries are not cached even after enabling query caching. To enable results caching for a particular query, call org.hibernate.Query.setCacheable(true)
Also read related questions about the query cache which explains some of the reasons for enabling the query cache. The Hibernate doc link above should also help explain the same.
-
2. Re: JPA query cache
whelan Feb 6, 2014 3:56 PM (in response to smarlow)But that means that this can not be done with the normal JPA 2.0 given by JEE 6?
Using JPA I use the entityManager and not a hibernate session.
How can I get access to the hibernate session through JPA 2.0?
-
3. Re: JPA query cache
kazaag Feb 6, 2014 4:28 PM (in response to whelan)You can activate implementation dependent feature with hints (setHint() on JPA query or via @NamedQueryHint annotation for name query). For hint for Hibernate (for the query) can be found here: Chapter 3. Working with objects
PS: it is easy to get the unerling implementation class: http://stackoverflow.com/questions/4148231/how-can-i-get-the-session-object-if-i-have-the-entitymanager
-
4. Re: JPA query cache
whelan Feb 7, 2014 5:39 AM (in response to kazaag)1 of 1 people found this helpfulHi François
Found the issue from the great links you have provided. Found out that I need to set the cacheMode in the queryHint. Had the cacheable but added the cacheMode:
query.setHint("org.hibernate.cacheable", true);
query.setHint("org.hibernate.cacheMode", "NORMAL");
Very much thank you for the help. I didn't need to go through the hibernate session