Patrick
Patrick

Reputation: 71

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

Upvotes: 5

Views: 12818

Answers (3)

Saul Berardo
Saul Berardo

Reputation: 2600

it has nothing to do with 2nd or Query caches, these are already disabled by default! What probably would help in your case is to call session.refresh(yourEntity) so that the state of your entity would be re-read by hibernate.

Upvotes: 1

Peter Tillemans
Peter Tillemans

Reputation: 35331

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.

Upvotes: 2

matt b
matt b

Reputation: 139921

I think the configuration you want is

hibernate.cache.use_query_cache = false

Reference.

Upvotes: 4

Related Questions