Why in the hibernate docs do I see references with both annotations on entities for caching?
eg: http://docs.jboss.org/hibernate/orm/4.2/manual/en-US/html_single/#performance-cache-mapping
@Entity
@Cacheable
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
public class Forest { ... }
Is both the @Cacheable and the @Cache annotations required?
if you are only using Hibernate, using only @Cache will do the trick, since @Cacheable is an another option you could use along with JPA or Spring.
@Cacheable is usually used for JPA Entities. In the docs, they are just referring to the @Cache annotation, so just focus on that.
Here is a good resource to look at for Hibernate Cache Levels: http://www.javacodegeeks.com/2012/02/hibernate-cache-levels-tutorial.html
Hope this helps. Tried my best :)
In short: no.
In long: @Cache is the cache interface provided by Hibernate, while @Cacheable is the interface provided by JPA specification. You can choose between one of them, and even use both. Note that @Cacheable will work only if your persistence.xml has caching element set to ENABLE_SELECTIVE or DISABLE_SELECTIVE.
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