Hibernate second level cache with Spring

前端 未结 3 1557
囚心锁ツ
囚心锁ツ 2020-12-08 03:23

I\'m using Spring + JPA + Hibernate. I\'m trying to enable Hibernate\'s second level cache. In my Spring\'s applicationContext.xml I have:

相关标签:
3条回答
  • 2020-12-08 03:56

    This link helped me for using second level cache with Hibernate 4

    0 讨论(0)
  • 2020-12-08 04:12

    Try this:

    <prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.max_fetch_depth">4</prop>
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    <prop key="hibernate.cache.use_query_cache">true</prop>
    <prop key="hibernate.cache.region.factory_class">net.sf.ehcache.hibernate.EhCacheRegionFactory</prop>
    

    And if you are using Maven add this to your POM file:

    <dependency>
      <groupId>net.sf.ehcache</groupId>
      <artifactId>ehcache-core</artifactId>
      <version>2.3.0</version>
    </dependency>
    

    Or download the latest jar from http://ehcache.org/

    0 讨论(0)
  • 2020-12-08 04:15

    I didn't answer this, but it's not obvious that the poster found the answer himself. I'm reposting his answer:

    Resolved

    Since I'm using LocalEntityManagerFactoryBean it gets its settings from META-INF/persistence.xml. My settings in applicationContext.xml weren't even being read.

    0 讨论(0)
提交回复
热议问题