我在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 {
...
}