How do I migrate cache related annotations from Hibernate 3.3.x to 3.6.x
My cache usage on entity Foo looked like this
@Entity
class Foo {
@ManyToOne(fetch = LAZY)
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.NONSTRIC开发者_JAVA百科T_READ_WRITE)
private Boo boo;
@OneToMany
@Cache(usage = org.hibernate.annotations.CacheConcurrencyStrategy.READ_WRITE)
private List<Bar> bars;
}
How should I migrate this code to support JPA 2 like annotations using Hibernate 3.6.5
I am aware that we are supposed to use @Cacheable
annotation at the entity level, but what should I use for cache declarations under
@ManyToOne and @OneToMany.
Remove your @Cache annotations and add to your 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>
References
- How to use JPA2's @Cacheable instead of Hibernate's @Cache
精彩评论