Is putting @Cacheable or @Cache above the Entity enough for Hibernate to start caching?

478 views Asked by At

Is it enough and Hibernate checks methods automatically that are doing stuff with that entity and updates the cache? Or @Cacheable, @CachePut, @CacheEvict annotations above methods are mandatory for a working cache.

1

There are 1 answers

0
Christian Beikov On BEST ANSWER

What is cached depends on the configuration. If you enable selective caching, you need to annotate all entities with @Cacheable that should be cached. For queries, you additionally need to provide a cache hint, but all of that can be read in the official documentation: https://docs.jboss.org/hibernate/orm/5.5/userguide/html_single/Hibernate_User_Guide.html#caching