This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
I have setup ehcache as hibernate query cache. But when I execute the same query multiple times, it still go and query the database (from the hibernate sql out, it still executes mysql query). Can you please tell me what am i missing?
Here is why I did in my hibernate.cfg.xml file: Add these: <property name="cache.provider_class"> org.hibernate.cache.EhCacheProvider </property> <property name="hibernate.cache.use_query_cache">true</property>
And then, here is my query: Query query = session .createQuery( "from Country as country where country.language= :language and country.phone.id = honeid");
Just to note, the query cache just stores the query and the ids in the result. The actual objects still need to be in the regular second level cache. If those objects are no longer there, then Hibernate has to get them from the database.
Joined: Nov 04, 2006
Thanks for your help. Add "<cache usage="read-only>" to my mapping file works.
However, there is a case where I expect hibernate to execute the query from the database instead of pull from the query cache, it does not work.
Here is the situation 1. execute a query 2. execute the same query again with no update to the database (expected) 3. add a row in the database via a legarcy application (non hibernate application). 4. execute a query (expected to re-execute the query instead of pulling the result from the database) This part does not work.
In the hiberante-in-action book, it talks about 'timestamp cache' on page 291. But I can't an example about that. I appreciate if you can help me.