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

标签 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.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/

相关文章:

mysql - 使用 Spring Data JPA 获取两个日期之间的记录

java - 金融应用程序中必需的货币数据类型?

java - JPA:@JoinColumn 和 @PrimaryKeyJoinColumn 之间的区别?

eclipse - 使用Spring+Hibernate部署Maven项目到Tomcat

mysql - 存储子查询的结果以用于多个连接

hibernate - 从Hibernate Grails中选择数据库

javascript - 有关 window.stop() 的详细信息

php - 使用 Varnish 缓存动态页面

Hibernate+GroovyTestcase : Unable to figure out the error in the code below . 。

java - 删除实体会导致 hibernate 中的 ObjectDeletedException