Sample Code: Please see our sample application for Hibernate 2nd Level Cache Config.

If you are using Hibernate with Hazelcast as a second level cache provider, you can easily configure your LocalSessionFactoryBean to use a Hazelcast instance by passing Hazelcast instance name. That way, you can use the same HazelcastInstance as Hibernate L2 cache instance.

...
<bean id="sessionFactory" 
      class="org.springframework.orm.hibernate3.LocalSessionFactoryBean" 
	  scope="singleton">
  <property name="dataSource" ref="dataSource"/>
  <property name="hibernateProperties">
      <props>
          ...
          <prop key="hibernate.cache.region.factory_class">com.hazelcast.hibernate.HazelcastLocalCacheRegionFactory</prop>
          <prop key="hibernate.cache.hazelcast.instance_name">${hz.instance.name}</prop>
      </props>
  </property>
  ...
</bean>

Hibernate RegionFactory Classes

  • com.hazelcast.hibernate.HazelcastLocalCacheRegionFactory
  • com.hazelcast.hibernate.HazelcastCacheRegionFactory

Please refer to Hibernate Configuring RegionFactory for more information.