I found some instructions how to configure pure hibernate to use EHCache. But I can’t find any instructions how to configure JPA2.0 EntityManager to use cache. Hibernate 3.5.2 is my JPA2.0 provider.
edit//
Is @Cacheable(true) enough for entity? Or should I use @org.hibernate.annotations.Cache to configure the entity?
The way you configure the L2 cache provider with JPA is similar is similar to raw Hibernate.
By default, Hibernate 3.5 ships with EhCache 1.5 (see Configure Ehcache as a Second Level Cache) and if you want to use the official cache provider provided by Hibernate (in
hibernate-ehcacheif you are using Maven), declare:If you want to use EhCache 2.x, you’ll need to use the provider provided by EhCache which supports the new Hibernate 3.3/3.5 SPI with its
CacheRegionFactory). Use:for instance creation, or
to force Hibernate to use a singleton of Ehcache CacheManager.
And then activate L2 caching and query caching:
That’s for the Hibernate L2 cache setup.
In theory, the
@Cacheableis supposed to be a replacement for the Hibernate proprietary annotation and should be used in conjunction with theshared-cache-modeelement:But as mentioned in this previous question, initial experimentation has not been successful (it might be related to HHH-5303, I can’t say, I didn’t investigate that much). So I suggest sticking with the proprietary annotations.
References
Resources
Related question