Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
H

hibernate-redis

> 数据库
Open source

hibernate 2nd level cache privder using redis

363 stars0 likes1 views
WebsiteGitHub

About

hibernate 2nd level cache privder using redis

hibernate-redis

hibernate (4.x, 5.1.x, 5.2.x) 2nd level cache provider using redis server 3.x. with Redisson 2.3.x

Reduce cache size by Redisson SnappyCodec (see snappy-java, Fast-Serialization)

Note

From 2.2.1 onwards Hibernate region naming (hibernate.cache.region_prefix) has been simplified to "hibernate".

hibernate-core 5.2.x based on Java 8, use hibernate-redis 2.2.0 or higher

Region factory for hibernate 5.2.x is hibernate.redis.cache.hibernate52.SingletonRedisRegionFactory

Setup

Maven Repository

add dependency

xml

    com.github.debop
    hibernate-redis
    2.3.2

Optional dependencies. Redisson support various codec (serializer, compression). you can choose other codec. see Redisson Help.

xml

    org.redisson
    redisson
    ${redisson.version}

    de.ruedigermoeller
    fst
    ${fst.version}

    org.xerial.snappy
    snappy-java
    ${snappy-java.version}
Setup hibernate configuration

Setup hibernate configuration (Note package name for hibernate 4 / hibernate 5 / hibernate52)

…

also same configuration for using Spring Framework or Spring Data JPA

Redis settings for hibernate-redis

sample for hibernate-redis.properties

ini
 ##########################################################
 #
 # properities for hibernate-redis
 #
 ##########################################################

 # Redisson configuration file
 redisson-config=conf/redisson.yaml

 # Cache Expiry settings
 # 'hibernate' is second cache prefix
 # 'common', 'account' is actual region name
 redis.expiryInSeconds.default=120
 redis.expiryInSeconds.hibernate.common=0
 redis.expiryInSeconds.hibernate.account=1200

sample for Redisson configuration (see more samples )

…

Hibernate configuration via Spring Application property files

In Spring applications, the hibernate- and hibernate-redis configuration represented above can be configured within Spring application property files like below.

…

Setup hibernate entity to use cache

add @org.hibernate.annotations.Cache annotation to Entity class like this

java
@Entity
@Cache(region="common", usage = CacheConcurrencyStrategy.READ_WRITE)  // or @Cacheable(true) for JPA
@Getter
@Setter
public class Item implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;

    private String description;

    private static final long serialVersionUID = -281066218676472922L;
}

How to monitor hibernate-cache is running

run "redis-cli monitor" command in terminal. you can see putting cached items, retrieving cached items.

Sample code

see hibernate-examples module

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

Javacachehibernateredisredisson

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category数据库
PricingOpen source

> Related tools

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库