We have given the simple cache code to understand the cache mapping. In 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"
/>
Tag description is given below:
Tag |
Description |
usage(required) |
It specifies the cache strategy. In transactional,read-write, nonstrict-read-write or read only |
region(optiona) |
Defaults to the classes or collection role name. It specifies the name of the second level cache region. |
include(optional) |
It defaults to all.It work non-lazy. It speficies that properties of teh entity mapped with lazy=”true” can not be cached when attribute-level lazy fetching is enabled. |
We can specify <class-cache> and <collection-cache> elements in hibernate.cfg.xml.The usage attribute specifies a cache concurrency strategy.