我在实体 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.CacheConcurrencyStrategy.READ_WRITE)
private List<Bar> bars;
}
我应该如何使用 Hibernate 3.6.5 迁移此代码以支持 JPA 2 之类的注释
我知道我们应该在实体级别使用 @Cacheable
注释,但是我应该在
@ManyToOne and @OneToMany.
最佳答案
删除 @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>
引用文献
关于hibernate - 如何将缓存相关注释从 Hibernate 3.3.x 迁移到 3.6.x,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6451553/