java.lang.NoClassDefFoundError: org/hibernate/cache/EntityRegion configuring EHCache

前端 未结 4 748
[愿得一人]
[愿得一人] 2020-12-16 11:21

I\'m trying to add ehcache (v2.6.0) to my Hibernate 4.1.5.SP1 project, but having some configuration issues. Specifically, I\'m getting a ja

相关标签:
4条回答
  • 2020-12-16 11:52
    Configuration.setProperty("hibernate.cache.region.factory_class", 
                         "net.sf.ehcache.hibernate.EhCacheRegionFactory")
    

    For Hibernate 4, use

    org.hibernate.cache.ehcache.EhCacheRegionFactory instead of net.sf.ehcache.hibernate.EhCacheRegionFactory
    

    Hibernate Configuration Article

    0 讨论(0)
  • 2020-12-16 12:05

    ehcache-core files are basically for Hibernate 3.x. Hibernate 4.x comes with its own implementation for ehcache. You don't need to use ehcache explicitly in hibernate 4.x. Here is the best answer for your problem.

    http://web.archive.org/web/20130117102553/http://www.javacraft.org/2012/03/migrate-to-hibernate-4-ehcache.html

    0 讨论(0)
  • 2020-12-16 12:12

    From Hibernate 4, there s new hibernate-cache introduce for caching. This need latest dependency for net.sf.ehcache upto 2.6. Following article will CLICK ON LINK. When i add following dependency in my pom, the error will remove:

        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>2.8.3</version>
        </dependency>
    
    0 讨论(0)
  • 2020-12-16 12:15

    I checked maven the dependencies. Maven always loads ehcache-code when the hibernate-ehcache package is loaded.

    Dependency tree:

    +--- org.hibernate:hibernate-ehcache:4.3.0.Final
    |    +--- org.jboss.logging:jboss-logging:3.1.3.GA
    |    +--- org.jboss.logging:jboss-logging-annotations:1.2.0.Beta1
    |    +--- org.hibernate:hibernate-core:4.3.0.Final (*)
    |    \--- net.sf.ehcache:ehcache-core:2.4.3
    |         \--- org.slf4j:slf4j-api:1.6.1 -> 1.6.6
    

    Please check your persistence configuration. It should not include any classes where the package name starts with "net.sf"

    For example, you have to replace the following string in your code:

    .setProperty("hibernate.cache.region.factory_class", "net.sf.ehcache.hibernate.EhCacheRegionFactory")
    

    with the following string:

    .setProperty("hibernate.cache.region.factory_class", "org.hibernate.cache.ehcache.EhCacheRegionFactory")
    
    0 讨论(0)
提交回复
热议问题