如何将缓存相关注释从Hibernate 3.3.x迁移到3.6.x

如何将缓存相关注释从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

我在实体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;
}

删除@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选择性
...
参考资料


JPA2没有为字段/属性定义缓存细节,只定义类;JDO是唯一定义缓存到字段级别的持久性规范。对不起,这没有回答这个问题。问题是如何为缓存注释集合。
<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>