Chapter 12. Hibernate Second Level Cache

Hazelcast provides distributed second level cache for your Hibernate entities, collections and queries. Hazelcast has two implementations of Hibernate 2nd level cache, one for hibernate-pre-3.3 and one for hibernate-3.3.x versions. In your Hibernate configuration file (ex: hibernate.cfg.xml), add these properties;

Hazelcast creates a seperate distributed map for each Hibernate cache region. So these regions can be configured easily via Hazelcast map configuration. You can define backup,eviction, TTL and Near Cache properties.

Hibernate has 4 cache concurrency strategies:read-only,read-write, nonstrict-read-write andtransactional. But Hibernate does not forces cache providers to support all strategies. And Hazelcast supports first three (read-only,read-write, nonstrict-read-write) of these four strategies. Hazelcast has not support for transactional strategy yet.

OR

Accessing underlying HazelcastInstance is possible by using HazelcastAccessor.

   SessionFactory sessionFactory = ...;
    HazelcastInstance hazelcastInstance = HazelcastAccessor.getHazelcastInstance(sessionFactory);        

And now last thing you should be aware of is to drop hazelcast-hibernate-<version>.jar into your classpath.