14.4. Hibernate 2nd Level Cache Config

If you are using Hibernate with Hazelcast as 2nd level cache provider, you can easily create CacheProvider or RegionFactory instances within Spring configuration. That way it is possible to use same HazelcastInstance as Hibernate L2 cache instance.

<hz:hibernate-cache-provider id="cacheProvider" instance-ref="instance" />
...

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" scope="singleton">
    <property name="dataSource" ref="dataSource"/>
    <property name="cacheProvider" ref="cacheProvider" />
    ...
</bean>

Or by Spring version 3.1

<hz:hibernate-region-factory id="regionFactory" instance-ref="instance" />
...
<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" scope="singleton">
    <property name="dataSource" ref="dataSource"/>
    <property name="cacheRegionFactory" ref="regionFactory" />
    ...
</bean>