Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hibernate disabling cache

Tags:

java

hibernate

I want to disable hibernate caching.

session.setCacheMode(CacheMode.IGNORE) doesn't work.
query.setCacheable(false) also doesn't work.

In addition, can I configure in some way that caching won't be done for Objects X,Y but will be done for Object Z?

Thanks.

like image 630
AAaa Avatar asked Apr 10 '26 04:04

AAaa


1 Answers

You can call session.clear() just before obtaining reusable session object from the manager.

I.e. in our project we had to synchronize updates between many hibernate sessions (one per http session). 2nd level cache works fine but 1st level (per session) had to be disabled or cleared. Thus we created SessionManager that stores all sessions and delivers on demand. Just before delivering call session.clear() and this solves the problem.

Until you're doing your unit of work - 1st level cache is fine.

like image 128
Valdas Rapševičius Avatar answered Apr 11 '26 19:04

Valdas Rapševičius



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!