hibernate-cache - 启动应用程序时显示“为可变实体配置的只读缓存”警告

标签 hibernate-cache

我在Hibernate4.2.1 Final中使用Spring3.2和JPA

我的实体代码之一是:

@Entity  
@Table(name = "BOOLEAN_VALUES")  
@Cache(region = "booleanValues", usage = CacheConcurrencyStrategy.READ_ONLY)  
public class BooleanValue {

    @Column(name = "NAME")  
    @NotEmpty  
    private String name;  

    public void setName(String name) {  
        this.name = name;  
    }  

    public String getName() {  
        return this.name;  
    }  
} 

我们想要缓存这种实体,因为它们的值永远不会改变。这些值将在应用程序启动之前插入表中。这些表看起来像字典值表。

我的ehcache.xml如下所示:
<cache name="booleanValues"   
           eternal="false" maxElementsInMemory="10000"   
           maxElementsOnDisk="1000"  
           overflowToDisk="true"   
           diskSpoolBufferSizeMB="20"   
           timeToIdleSeconds="3000"   
           timeToLiveSeconds="6000"  
           memoryStoreEvictionPolicy="LFU" />  

但是,每次我启动应用程序时,都会显示以下警告,我的配置是否存在任何问题?如何将这些实体设置为不可变的?
2013-08-21 09:36:18,983 - org.hibernate.cache.ehcache.internal.strategy.EhcacheAccessStrategyFactoryImpl -2921 [localhost-startStop-1] WARN   - HHH020007: read-only cache configured for mutable entity [booleanValues] 

最佳答案

@Entity注释您的@org.hibernate.annotations.Immutable

@Entity  
@Immutable
@Table(name="BOOLEAN_VALUES")  
@Cache(region="booleanValues", usage=CacheConcurrencyStrategy.READ_ONLY)  
public class BooleanValue {

  ...

}

关于hibernate-cache - 启动应用程序时显示“为可变实体配置的只读缓存”警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18352182/

相关文章:

当条件暗示日期时,Hibernate 查询缓存不起作用

hibernate - Hibernate 2级缓存不适用于GORM 6.1.11

java - 当 Redis 连接出现问题时,在 Hibernate 中熔断 L2 缓存

caching - Ehcache从2.6迁移到3.00

java - 当我们使用 hibernate 5.3.1.Final 依赖项在 hibernate.cfg.xml 文件中启用查询缓存时,为什么会出现异常?

java - Hibernate 二级缓存和 JUnit

spring - 使用 Hibernate L2 ehcache 和 spring bootenabledCache 时已经存在另一个未命名的 CacheManager

java - 查询 Hibernate 缓存