【问题标题】:How do I migrate cache related annotations from Hibernate 3.3.x to 3.6.x如何将缓存相关的注释从 Hibernate 3.3.x 迁移到 3.6.x
【发布时间】:2011-09-21 01:08:48
【问题描述】:

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

我应该如何迁移此代码以支持 JPA 2,例如使用 Hibernate 3.6.5 的注释

我知道我们应该在实体级别使用@Cacheable 注释,但是我应该在

下使用缓存声明
@ManyToOne and @OneToMany.

【问题讨论】:

  • JPA2 没有定义字段/属性的缓存细节,只是类; JDO 是唯一定义缓存到字段级别的持久性规范

标签: hibernate caching jpa jpa-2.0 second-level-cache


【解决方案1】:

删除您的 @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>

参考文献

【讨论】:

  • 不,抱歉,没有回答这个问题。问题是询问如何注释集合以进行缓存。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2017-12-11
  • 1970-01-01
  • 2021-12-31
  • 2016-04-04
  • 1970-01-01
  • 1970-01-01
  • 2020-08-24
相关资源
最近更新 更多