如何将缓存相关注释从Hibernate 3.3.x迁移到3.6.x
我在实体Foo上的缓存使用情况如下所示如何将缓存相关注释从Hibernate 3.3.x迁移到3.6.x,hibernate,caching,jpa,jpa-2.0,second-level-cache,Hibernate,Caching,Jpa,Jpa 2.0,Second Level Cache,我在实体Foo上的缓存使用情况如下所示 @Entity class Foo { @ManyToOne(fetch = LAZY) @Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE) private Boo boo; @OneToMany @Cache(usage = org.hibernate.annotations.CacheC
@Entity
class Foo {
@ManyToOne(fetch = LAZY)
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
private Boo boo;
@OneToMany
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
private List<Bar> bars;
}
删除@Cache注释并添加到persistence.xml中:
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="FooPu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
...
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>
org.hibernate.ejb.HibernatePersistence
...
启用\u选择性
...
参考资料
<persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0">
<persistence-unit name="FooPu" transaction-type="RESOURCE_LOCAL">
<provider>org.hibernate.ejb.HibernatePersistence</provider>
...
<shared-cache-mode>ENABLE_SELECTIVE</shared-cache-mode>
<properties>
...
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.SingletonEhCacheProvider"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.use_query_cache" value="true"/>
</properties>
</persistence-unit>
</persistence>