hibernate - @Cache 注释使用错误

标签 hibernate caching ejb-3.0 ehcache java-ee-5

我添加了以下注释以启用缓存到我的 EJB3 实体之一,以使用 ehCache 测试缓存,其中我使用 Hibernate 作为持久性提供程序:

....
import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

@Entity
@Table(name = "F")
@Cache(usage=CacheConcurrencyStrategy.READ_WRITE)
@NamedQueries({ @NamedQuery(name = "F.findAll", query = "SELECT f FROM F f")})
public class F implements Serializable {
   .....
}

我在persistence.xml中添加了以下内容:
<property name="hibernate.cache.provider_class" value="org.hibernate.cache.EhCacheProvider"/>
<property name="hibernate.cache.provider_configuration_file_resource_path" value="/ehcache.xml"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>

当我尝试编译时,出现以下错误:

/persistence/F.class): warning: Cannot find annotation method 'usage()' in type 'org.hibernate.annotations.Cache': class file for org.hibernate.annotations.Cache not found An exception has occurred in the compiler (1.6.0_16). Please file a bug at the Java Developer Connection (http://java.sun.com/webapps/bugreport) after checking the Bug Parade for duplicates. Include your program and the following diagnostic in your report. Thank you. com.sun.tools.javac.code.Symbol$CompletionFailure: class file for org.hibernate.annotations.CacheConcurrencyStrategy not found



任何人都可以在这里帮助我,让我知道我需要做什么或目前做错了什么?

最佳答案

@org.hibernate.annotations.Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)

将解决问题

关于hibernate - @Cache 注释使用错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1613952/

相关文章:

java - EJB 删除实体不起作用

java - 生成列表中的大量数据并生成文件

Spring Data JPA PageRequest 按 Map 值属性排序

xml - Hibernate 写入 XML 数据库

c - 与缓存行对齐并了解缓存行大小

javascript - 类型 'get' 上不存在属性 'Cache' 。 NestJs 项目

spring - EJB3 拦截器无法引导上下文

java - "jta-datasource"和 "resource-local "数据源之间的区别?

java - 我需要将 hibernate 与 mongoDB 连接。请提供 mongoDB 的 hibernate.cfg。我有一个,但它不起作用

java - wildfly8.2、hibernate-entitymanager 4.3.8.Final中的JPA二级缓存