Spring Boot JPA Hibernate second cache level

Hi all)

I’m tired of implementing the Hibernate second-level cache (
I tried to implement ehcache, Hazelcast, Infinispan, Caffeine etc…, but Hibernate always goes to db for data.
I have to implement inmemory second cache level also query cache.

Could you please give me some advices or working examples links?
Appreciate

PP: Spring Boot 2.7.14, Hibernate 5.6.8.Final

I’m sure you’ve seen the documentation chapter about this topic which tells you that there are more or less 2 kinds of caches. The second level cache and the query cache. The second level cache will cache entity state based on the primary key which is useful for “by-id lookup” i.e. EntityManager#find(). The query cache will cache the result of a query, but in addition to enabling query caching in general, you also have to enable that on a query with Query#setHint( "org.hibernate.cacheable", "true"). There are plenty of tutorials online that even point to example code. You just have to read the tutorials, follow the links and build the test projects. Let Me Google That

1 Like

Hi)
Thanks a lot! You made my day! Appreciate it

вт, 17 окт. 2023 г. в 09:35, Christian Beikov via Hibernate <notifications@hibernate.discoursemail.com>: