Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hibernate disable Query Cache

Following problem:

I create a Query to display all Entries of a MYSQL Table, if I edit a Field and execute the Query again I get the same (old) Result as in the first query.

It seems that Hibernate caches the Result. I tried to disable Caching with

query.setCachable(false)

"hibernate.cache.use_second_level_cache"

"cache.provider_class"

"org.hibernate.cacheable"

flushing and closing the session

but nothing works

like image 324
Patrick Avatar asked Jun 24 '10 13:06

Patrick


People also ask

How do I disable Hibernate caching?

To disable second-level caching (say for debugging purposes), we just set the hibernate. cache. use_second_level_cache property to false.

Is query level caching mandatory in Hibernate?

A - Query level cache is an optional feature.

Is Hibernate supports query cache?

The Hibernate query cache is supported. Every cache provider is not compatible with every concurrency strategy.

Can we disable first level cache in Hibernate?

Hibernate first level cache is enabled by default and there is no way to disable it. However hibernate provides methods using which selected objects can be deleted from the cache or clear the cache completely.


2 Answers

I think the configuration you want is

hibernate.cache.use_query_cache = false

Reference.

like image 192
matt b Avatar answered Sep 23 '22 09:09

matt b


Could it be that you never saved or updated the the changed entry to hibernate? When the cache returns the wrong result that is usually an indication something else is wrong.

like image 39
Peter Tillemans Avatar answered Sep 24 '22 09:09

Peter Tillemans