Second-Level Cache for Hibernate

Hibernate stores data in first-level (L1) cache to minimize expensive database requests. However, this data is cached per Hibernate session and is not shared among threads. A common solution here is to configure a second-level (L2) cache.

Ignite In-Memory Data Grid can be plugged in as Hibernate second-level (L2) cache. Accessible by all sessions, Ignite Data Grid can significantly accelerate the performance of your application by reducing the data access time.

How Hibernate Caching Works

Hibernate first-level (L1) cache is associated with the session object, the scope of which is limited to a single session. Objects cached in one session are not shared with another, which means that a request for the same entity by another session will still go to the database.

Ignite as Hibernate L2 Cache

To overcome the issue of per-session cache, a global second-level (L2) cache can be configured, in which cached objects are visible to all sessions. This usually gives a significantly greater performance gain since each newly created session now has access to the data already present in the L2 cache memory.

Apache Ignite can be plugged-in as Hibernate L2 cache implementation, and can be used in all access modes - READ_ONLY, READ_WRITE, NONSTRICT_READ_WRITE, and TRANSACTIONAL, supporting a wide range of related features:

  • On-Heap and Off-Heap in-memory stores, as well as disk overflow.
  • Cache transactions, that make TRANSACTIONAL mode possible.
  • Clustering, with 2 different replication modes: REPLICATED and PARTITIONED

Configure Hibernate L2 Cache