Spring Data + Hibernate-Query-Caching funktioniert nicht

Ich versuche aber, nicht erfolgreich zu cache eine Abfrage in Frühjahr Daten und Hibernate environmet mit folgenden Abhängigkeiten :

compile 'org.hibernate:hibernate-validator:4.0.0.GA'
compile 'org.hibernate:hibernate-entitymanager:3.6.6.Final'
compile 'org.hibernate.javax.persistence:hibernate-jpa-2.0-api:1.0.0.Final'
compile 'org.hibernate:hibernate-ehcache:3.3.1.GA'
compile 'org.springframework.data:spring-data-jpa:1.2.0.RELEASE'

Meine Spring Data Repository(ServiceRepository) für die Entität Service ist

public interface ServiceRepository extends CrudRepository<Service, Long>, JpaSpecificationExecutor<Service> {
    @Cacheable("merchantServices")
    @Query("select s from Service s JOIN s.statusList sas where s.status=?1 and s.priviligedUser.priviligedUserType IN (2,4) and (s.id IN (select st.id from Service st inner join st.tags tag where tag IN (?3)) or s.serviceType IN (?2)) and sas.active=true and sas.transactorType=?4 ORDER BY s.name")
    List<Service> getAllMerchantServicesByStatusTypeAndTags(ServiceStatus status, List<ServiceType> type, List<String> tags, TransactorType transactor);
}

Repositorys @Cacheable Methode aufgerufen wird, von

public List<Service> getAllServicesByStatusAndId(ServiceStatus status, List<Long> services, TransactorType transactor) {
    return serviceRepository.getAllMerchantServicesByStatusAndServiceId(status, services, transactor);
}

Meine Caching-confing (jpa-context.xml) ist

Es ist inspiriert von spring-data-jpa-examples/src/main/resources/caching-repository-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns:p="http://www.springframework.org/schema/p" 
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xmlns:cache="http://www.springframework.org/schema/cache" 
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd  
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/cache
        http://www.springframework.org/schema/cache/spring-cache.xsd"
    default-autowire="byName">

    <tx:annotation-driven />

    <bean id="cacheManager" class="org.springframework.cache.support.SimpleCacheManager">
      <property name="caches">
         <set>
          <bean class="org.springframework.cache.concurrent.ConcurrentMapCacheFactoryBean" p:name="merchantServices"/>
        </set>
      </property>
    </bean>
</beans>

- cache aktiviert Hibernate config (hibernate.cfg.xml) ist

<?xml version='1.0' encoding='utf-8'?>
<!DOCTYPE hibernate-configuration PUBLIC
        "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
        "http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<hibernate-configuration>
    <session-factory>
        <property name="hibernate.default_batch_fetch_size">16</property>
        <property name="hibernate.max_fetch_depth">5</property>

        <property name="hibernate.cache.use_query_cache">true</property>
        <property name="hibernate.cache.use_second_level_cache">true</property>
        <property name="hibernate.generate_statistics">true</property>
        <property name="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</property> 
        <property name="hibernate.c3p0.timeout">300</property>

    </session-factory>
</hibernate-configuration>

Betrachten Protokoll; jedes mal, wenn ich Anfrage, ich sehe die Abfrage ausgeführt.

17:50:28.997 [http-bio-8080-exec-10] INFO  org.hibernate.stat.Statistics - HQL: select s from Service s JOIN s.statusList sas where s.status=?1 and s.priviligedUser.priviligedUserType IN (2,4) and s.id IN (?2) and sas.active=true and sas.transactorType=?3 ORDER BY s.name, time: 57ms, rows: 1

Nächste mal bitte ich Sie, sehe ich folgende Abfrage;

18:03:40.374 [http-bio-8080-exec-8] INFO  org.hibernate.stat.Statistics - HQL: select s from Service s JOIN s.statusList sas where s.status=?1 and s.priviligedUser.priviligedUserType IN (2,4) and s.id IN (?2) and sas.active=true and sas.transactorType=?3 ORDER BY s.name, time: 47ms, rows: 1

Referenzen

spring-Projekte/spring-data-jpa-Beispiele

Spring 3.1-Caching und Config

Spring Data Rest - Caching

Spring Data Repository Zwischenspeichern der Ergebnisse

InformationsquelleAutor prayagupd | 2013-09-18
Schreibe einen Kommentar