Hibernate Second-Level Cache
Use GridGain 8 as the second-level cache of Hibernate ORM 7.4 with the ignite-hibernate-7.4 module.
You can use GridGain as the second-level (L2) cache of Hibernate ORM 7.4. The L2 cache keeps entities, collections, and query results in GridGain caches, so every application server that shares a GridGain cluster also shares the cached data. This reduces the number of queries that reach the underlying database.
The integration is provided by the ignite-hibernate-7.4 module. The module uses the Jakarta Persistence (jakarta.persistence) namespace.
Adding the Module to Your Application
The region factory runs inside your application, next to Hibernate. Add the ignite-hibernate-7.4 module to the application as a Maven dependency:
<properties>
<gridgain.version>8.10</gridgain.version>
</properties>
<dependencies>
<dependency>
<groupId>org.gridgain</groupId>
<artifactId>ignite-hibernate-7.4</artifactId>
<version>${gridgain.version}</version>
</dependency>
</dependencies>The module depends on ignite-core and org.hibernate.orm:hibernate-core 7.4. For the GridGain Maven repository and the other GridGain dependencies, see Using Maven.
If you start the GridGain node from a Spring XML configuration file (see Connecting to a GridGain Node), also add the ignite-spring module.
Enabling the L2 Cache
To enable the L2 cache, set the following Hibernate properties:
hibernate.cache.use_second_level_cache- set totrue.hibernate.cache.region.factory_class- set toorg.apache.ignite.cache.hibernate.IgniteRegionFactory.
Then tell the region factory which GridGain node to use. For details, see Connecting to a GridGain Node.
The following example shows a minimal hibernate.cfg.xml file that attaches the L2 cache to a node named hibernate-grid:
You can set the same properties in a hibernate.properties file, in persistence.xml, or in any other Hibernate settings source:
Connecting to a GridGain Node
The region factory gets its caches from a GridGain node in the same JVM. You can attach it to a node that your application starts, or let the region factory start the node:
Attach to a running node. Start the node in your application before you build the Hibernate
SessionFactory, and sethibernate.cache.ignite.instance_nameto the node's instance name. If you set neitherinstance_namenorconfiguration, the region factory attaches to the node started without an instance name. The node keeps running when theSessionFactoryis closed.Start a node. Set
hibernate.cache.ignite.configurationto the path or URL of a GridGain Spring XML configuration file. The region factory starts a node from that file and stops it when theSessionFactoryis closed. This option requires theignite-springmodule on the application classpath. If both properties are set,configurationis used.
The node is usually a client node that joins your GridGain cluster. The cached data is then stored on the cluster's server nodes and shared by every application that connects to the cluster.
Configuration Properties
All GridGain-specific properties start with the hibernate.cache.ignite. prefix.
hibernate.cache.ignite.instance_name
The instance name of a running GridGain node to attach to.
None
hibernate.cache.ignite.configuration
The path or URL of a GridGain Spring XML configuration file. The region factory starts a node from this file. Takes precedence over instance_name.
None
hibernate.cache.ignite.cache_name_prefix
A prefix added to the name of every GridGain cache that backs a Hibernate region.
None
hibernate.cache.ignite.region.<region-name>
Maps the Hibernate region <region-name> to a GridGain cache with the given name. Regions without a mapping use a cache named after the region.
None
hibernate.cache.ignite.default_access_type
The concurrency strategy for entities and collections that do not declare one. Accepted values: READ_ONLY, READ_WRITE, NONSTRICT_READ_WRITE.
READ_WRITE
Concurrency Strategies
The GridGain L2 cache supports the following Hibernate cache concurrency strategies:
READ_ONLYREAD_WRITENONSTRICT_READ_WRITE
The TRANSACTIONAL strategy is not supported. If you set hibernate.cache.ignite.default_access_type to TRANSACTIONAL, the SessionFactory fails to start.
Declare the strategy on each cached entity or collection with the standard Hibernate annotations:
Mapping Regions to GridGain Caches
Hibernate stores cached data in regions. The region factory backs each region with a GridGain cache:
An entity is cached in a region named after the fully qualified entity class name, for example
com.example.User, unless you set a region explicitly with@Cache(region = "...").Query results and update timestamps are cached in their own regions when the query cache is enabled.
By default, the GridGain cache has the same name as the region, with the optional cache_name_prefix in front of it. To use a different cache, map the region with the hibernate.cache.ignite.region.<region-name> property:
In this example, the com.example.User entity is cached in the hib_user-cache GridGain cache.
If a cache with the resulting name does not exist, the region factory creates it with the default cache configuration. To control backups, the atomicity mode, expiration, or other cache settings, define the caches in the node configuration with the same names:
unsupported
unsupported
For more information about cache settings, see Cache Configuration.
This page is: Copyright © 2026 MariaDB. All rights reserved.
Last updated
Was this helpful?

