Results 1 to 2 of 2

Thread: Hibernate second level cache with Spring

  1. #1
    Join Date
    Jan 2009
    Posts
    6

    Default Hibernate second level cache with Spring

    I'm using Spring + JPA + Hibernate. I'm trying to enable Hibernate's second level cache. In my Spring's applicationContext.xml I have:
    Code:
    <prop key="hibernate.cache.provider_class">net.sf.ehcache.hibernate.SingletonEhCacheProvider</prop>
    <prop key="hibernate.cache.provider_configuration_file_resource_path">/ehcache.xml</prop>
    When I run I get the error:
    Code:
    Caused by: org.hibernate.HibernateException: Could not instantiate cache implementation
         at org.hibernate.cache.CacheFactory.createCache(CacheFactory.java:64)
    Caused by: org.hibernate.cache.NoCachingEnabledException: Second-level cache is not enabled for usage [hibernate.cache.use_second_level_cache | hibernate.cache.use_query_cache]
         at org.hibernate.cache.NoCacheProvider.buildCache(NoCacheProvider.java:21)
    So it's complain I don't have second level cache enabled. So I add to my applicationContext.xml to enable it:
    Code:
    <prop key="hibernate.cache.use_second_level_cache">true</prop>
    But still no joy. I also tried adding this to my ehcache.xml:
    Code:
    <property name="hibernate.cache.use_second_level_cache">true</property>
    But it still doesn't work.

    My entity classes are annotated to use caching
    Code:
    @Cache(usage=CacheConcurrencyStrategy.READ_ONLY)
    Changing the provider_class to org.hibernate.cache.EhCacheProvider doesn't help:
    Code:
    <prop key="hibernate.cache.provider_class">org.hibernate.cache.EhCacheProvider</prop>
    So, how do I enable second level cache?

    Thanks, Steve

  2. #2
    Join Date
    Jan 2009
    Posts
    6

    Default

    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.

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •