public class HibernateCollectionRegion extends HibernateTransactionalDataRegion implements org.hibernate.cache.spi.CollectionRegion
CollectionRegion
. This region is used to store collection data.
L2 cache for collection can be enabled in the Hibernate configuration file:
<hibernate-configuration> <!-- Enable L2 cache. --> <property name="cache.use_second_level_cache">true</property> <!-- Use Ignite as L2 cache provider. --> <property name="cache.region.factory_class">org.apache.ignite.cache.hibernate.HibernateRegionFactory</property> <!-- Specify entities. --> <mapping class="com.example.Entity"/> <mapping class="com.example.ChildEntity"/> <!-- Enable L2 cache with nonstrict-read-write access strategy for entities and collection. --> <collection-cache collection="com.example.Entity" usage="nonstrict-read-write"/> <collection-cache collection="com.example.ChildEntity" usage="nonstrict-read-write"/> <collection-cache collection="com.example.Entity.children" usage="nonstrict-read-write"/> </hibernate-configuration>Also cache for collection can be enabled using annotations:
@javax.persistence.Entity public class Entity { ... @javax.persistence.OneToMany(cascade=CascadeType.ALL, fetch=FetchType.EAGER) @javax.persistence.JoinColumn(name="PARENT_ID") @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) public List<ChildEntity> getChildren() {...} }Note: the collection cache does not cache the state of the actual entities in the cache, it caches only identifier values. For this reason, the collection cache should always be used in conjunction with the second-level cache for those entities expected to be cached as part of a collection cache.
cache, factory, ignite
Constructor and Description |
---|
HibernateCollectionRegion(HibernateRegionFactory factory,
String name,
Ignite ignite,
HibernateCacheProxy cache,
org.hibernate.cache.spi.CacheDataDescription dataDesc) |
Modifier and Type | Method and Description |
---|---|
org.hibernate.cache.spi.access.CollectionRegionAccessStrategy |
buildAccessStrategy(org.hibernate.cache.spi.access.AccessType accessType) |
getCacheDataDescription, isTransactionAware
contains, destroy, getElementCountInMemory, getElementCountOnDisk, getName, getSizeInMemory, getTimeout, nextTimestamp, toMap
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
public HibernateCollectionRegion(HibernateRegionFactory factory, String name, Ignite ignite, HibernateCacheProxy cache, org.hibernate.cache.spi.CacheDataDescription dataDesc)
factory
- Region factory.name
- Region name.ignite
- Grid.cache
- Region cache.dataDesc
- Region data description.public org.hibernate.cache.spi.access.CollectionRegionAccessStrategy buildAccessStrategy(org.hibernate.cache.spi.access.AccessType accessType) throws org.hibernate.cache.CacheException
buildAccessStrategy
in interface org.hibernate.cache.spi.CollectionRegion
org.hibernate.cache.CacheException
Follow @ApacheIgnite
Ignite Database and Caching Platform : ver. 2.7.2 Release Date : February 6 2019