6

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?

2 Answers 2

5

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 :)

Sign up to request clarification or add additional context in comments.

1 Comment

as you said both is diff term in diff api's.
2

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.