2013-08-21 20 views
3

我使用Spring3.2和JPA與Hibernate4.2.1最終「配置可變的實體只讀緩存」警告時顯示應用程序啓動

我的一個實體的代碼是這樣的:

@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] 

回答

6

註解你@Entity@org.hibernate.annotations.Immutable

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

    ... 

} 
相關問題