On the other hand, the documentation provided by EH Cache always refer to the newest version, which doesn't always work with the one shipped by Hibernate.
In a nutshell, getting Hibernate to work with EH Cache involves the following steps:
- Setting up EH Cache:
- Use the ehcache.jar file provided by Hibernate.
- Need to download backport-util-concurrent.jar (Latest version is 3.1 at time of writing and seems to work fine).
- Configure ehcache.xml and put it on the classpath. It should have a "defaultCache" element as a template and then a separate "cache" element for each entity class (with fully qualified class name as the "name" of the cache).
- For the query cache, add a "cache" element with name "org.hibernate.cache.StandardQueryC
ache". - Configure cache behavior as desired.
- On Hibernate's side:
- In hibernate.cfg.xml, add the following lines (subtle differences with documentation due to older version of EH Cache used and things Hibernate did when packaging EH Cache.):
- <property name="cache.use_second_level_cache">true<
/property> - <property name="cache.use_query_cache">true</prope
rty> - <property name="cache.provider_class">org.hibernat
e.cache.SingletonEhCacheProvider</proper ty>
- <property name="cache.use_second_level_cache">true<
- And then in the mapping file for each entity (in the "class" element), add (above the "id" and "property" elements):
- <cache usage="read-write" />
- In hibernate.cfg.xml, add the following lines (subtle differences with documentation due to older version of EH Cache used and things Hibernate did when packaging EH Cache.):
No comments:
Post a Comment