Попытка настроить кеш второго уровня с помощью Spring и Hibernate.Кэш второго уровня: Spring 3.2.2 + Hibernate 4.2.0 Infinispan
<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="jpaVendorAdapter">
<bean class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter" p:database="${jdbc.databaseType}" p:generateDdl="true"
p:showSql="true"/>
</property>
<property name="jpaProperties">
<props>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.enable_lazy_load_no_trans">true</prop>
<prop key="hibernate.ejb.naming_strategy">com.antaresgames.ad.lobby.repository.FixedDefaultComponentSafeNamingStrategy</prop>
<prop key="hibernate.transaction.manager_lookup_class">org.hibernate.cache.infinispan.tm.HibernateTransactionManagerLookup</prop>
<prop key="hibernate.transaction.jta.platform">org.hibernate.service.jta.platform.internal.JBossStandAloneJtaPlatform</prop>
<prop key="hibernate.transaction.factory_class">org.hibernate.transaction.JTATransactionFactory</prop>
<!--https://docs.jboss.org/author/display/ISPN/Using+Infinispan+as+JPA-Hibernate+Second+Level+Cache+Provider-->
<!--CACHE CONFIGURATION-->
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.use_query_cache">false</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.JndiInfinispanRegionFactory</prop>
<prop key="hibernate.cache.infinispan.cachemanager">java:Cachemanager</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.infinispan.InfinispanRegionFactory</prop>
<prop key="hibernate.cache.infinispan.statistics">true</prop>
<!--https://docs.jboss.org/author/display/ISPN/Eviction-->
<!--<prop key="hibernate.cache.infinispan.entity.eviction.strategy">LIRS</prop>-->
<!--https://docs.jboss.org/author/display/ISPN/Eviction+Examples-->
<!--<prop key="hibernate.cache.infinispan.entity.eviction.wake_up_interval">2000</prop>-->
<!--https://docs.jboss.org/author/display/ISPN/Eviction-->
<!--<prop key="hibernate.cache.infinispan.entity.eviction.max_entries">5000</prop>-->
<!--max time entity is living in memory in idle-->
<!--<prop key="hibernate.cache.infinispan.entity.expiration.max_idle">60000</prop>-->
</props>
</property>
</bean>
Но из-за отсутствия documentation для Hibernate 4, я думаю, что я не могу настроить кэш должным образом.
При запуске приложения я вижу предупреждение как:
jta.JtaTransaction - HHH000426: You should set hibernate.transaction.manager_lookup_class if cache is enabled
И при получении объекта для репозитория делает каждый раз запроса.
Любые предложения?
Попробуйте удалить 'hibernate.transaction.manager_lookup_class' и' hibernate.transaction.factory_class'. Это старые свойства. Если вы используете Hibernate 4+, вам просто нужно 'hibernate.transaction.jta.platform'. Кроме того, вы дважды задали 'hibernate.cache.region.factory_class'. Удалите файл с 'org.hibernate.cache.infinispan.InfinispanRegionFactory' и удалите свойство' hibernate.cache.infinispan.cachemanager' –