Hibernate query cache and consistency issues


#1

Hi Vlad,

I was reading through your post https://vladmihalcea.com/how-does-hibernate-query-cache-work/ about the query cache in which it is mentioned in the end that hibernate cache is susceptible to consistency issues. Is this only when mixing the native SQL queries with HQL queries?
Or the query cache is susceptible to consistency even when using only the HQL queries?


#2

For HQL, it’s fine if all changes happen through Hibernate.

For native SQL, you need to use the tablespace synchronization methods to avoid consistency issues.

If you do that properly, you should be fine.


#3

Does Hibernate query cache stores results in a cache for every parameter value of predicate?
e.g. select address from author where name = ?
for above query, will the query cache store results for all the name value that are used in above query and all those results will be cached for each parameter value?


#4

Yes. For a detailed explanation, check out this article.