2011-06-23 2 views
4

Mon utilisation du cache sur l 'entité Foo ressemblait à ceComment migrer les annotations associées au cache d'Hibernate 3.3.x à 3.6.x

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

Comment dois-je migrer ce code pour soutenir JPA 2 comme des annotations en utilisant Hibernate 3.6 0,5

Je suis conscient que nous sommes censés utiliser l'annotation @Cacheable au niveau de l'entité, mais que dois-je utiliser pour les déclarations de cache sous

@ManyToOne and @OneToMany. 
+4

JPA2 ne définit pas les détails de mise en cache pour les champs/propriétés, à quelques classes; JDO est la seule spécification de persistance définissant la mise en cache jusqu'au niveau du champ. – DataNucleus

Répondre

0

Retirez votre @ annotations cache et ajouter à votre 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> 

Références

+0

Non, désolé, cela ne répond pas à la question. La question est de savoir comment annoter les collections pour la mise en cache. –

Questions connexes