我添加了以下注释以启用缓存到我的 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/