How to transfer cache-related annotations from Hibernate 3.3.x to 3.6.x

My use of cache in essence Foo was as follows

@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; } 

How do I port this code to support JPA 2 as annotations using Hibernate 3.6.5

I know that we should use @Cacheable annotation at the entity level, but what should I use for cache declarations in

 @ManyToOne and @OneToMany. 
+4
source share
1 answer

Remove the @Cache annotations and add persistence.xml to your file:

 <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

0
source

All Articles