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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With