本文共 653 字,大约阅读时间需要 2 分钟。
Hibernate应用中,设置二级缓存的并发策略有两种方法,一种是通过Hibernate的全局配置文件,另一种是为各个Entity类单独设置。
1. 通过hibernate.cache.default_cache_concurrency_strategy配置参数,设置全局的二级缓存的并发策略
hibernate.cache.default_cache_concurrency_strategy配置参数的可用值:
- read-only,适合只读事务
- read-write,适合读写事务
- nonstrict-read-write,适合高并发的读写事务
- transactional,事务序列化
2. 使用Cache标注为各个Entity类单独设置二级缓存的并发策略
- @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_ONLY)
- @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
- @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
- @org.hibernate.annotations.Cache(usage = CacheConcurrencyStrategy.TRANSACTIONAL)
转载地址:http://dslai.baihongyu.com/