You have the option to tell Hibernate which caching implementation to use by specifying the name of a class that implements org.hibernate.cache.CacheProvider
using the property hibernate.cache.provider_class
. Hibernate comes bundled with a number of built-in integrations with open-source cache providers (listed below); additionally, you could implement your own and plug it in as outlined above. Note that versions prior to 3.2 defaulted to use EhCache as the default cache provider; that is no longer the case as of 3.2.
The <cache>
element of a class or collection mapping has the following form:
<cache
usage="transactional|read-write|nonstrict-read-write|read-only"
region="RegionName"
include="all|non-lazy"
/>
usage
(required) specifies the caching strategy: transactional
, read-write
, nonstrict-read-write
or read-only
region
(optional, defaults to the class or collection role name) specifies the name of the second level cache region
include
(optional, defaults to all
) non-lazy
specifies that properties of the entity mapped with lazy="true"
may not be cached when attribute-level lazy fetching is enabled
Alternatively (preferrably?), you may specify <class-cache>
and <collection-cache>
elements in hibernate.cfg.xml
.
The usage
attribute specifies a
cache concurrency strategy
.