Pergunta

In my project I am upgrading the hibernate version 3.2 to 4.1(which is default provided in the JBoss EAP 6.0) and setting my ehcache version to 2.8.0.

I have added the hibernate-ehcache-4.2.8.Final.jar to the classpath(web-inf/lib/) and changed my config for the ehcache like this,

<prop key="hibernate.cache.region.factory_class">
                org.hibernate.cache.ehcache.EhCacheRegionFactory
            </prop>
            <prop key="net.sf.ehcache.configurationResourceName">ehcache.xml</prop>

for loading the Hibernate Classes in classpath I have added dependency in the jboss-deployment-structure.xml like this.

 <module name="org.hibernate" export="true"/>
<module name="org.hibernate.commons-annotations" export="true"/>

But when starting server I'm facing this error,

Caused by: org.hibernate.service.classloading.spi.ClassLoadingException: Unable to load class [org.hibernate.cache.ehcache.EhCacheRegionFactory]
at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:141) [hibernate-core-4.1.3.Final-redhat-1-JBPAPP-9359.jar:4.1.4-SNAPSHOT]
at org.hibernate.cfg.SettingsFactory.createRegionFactory(SettingsFactory.java:386) [hibernate-core-4.1.3.Final-redhat-1-JBPAPP-9359.jar:4.1.4-SNAPSHOT]
... 68 more
Caused by: java.lang.ClassNotFoundException: Could not load requested class : org.hibernate.cache.ehcache.EhCacheRegionFactory
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl$1.findClass(ClassLoaderServiceImpl.java:99) [hibernate-core-4.1.3.Final-redhat-1-JBPAPP-9359.jar:4.1.4-SNAPSHOT]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:423) [rt.jar:1.7.0_05]
    at java.lang.ClassLoader.loadClass(ClassLoader.java:356) [rt.jar:1.7.0_05]
    at java.lang.Class.forName0(Native Method) [rt.jar:1.7.0_05]
    at java.lang.Class.forName(Class.java:264) [rt.jar:1.7.0_05]
    at org.hibernate.service.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:138) [hibernate-core-4.1.3.Final-redhat-1-JBPAPP-9359.jar:4.1.4-SNAPSHOT]
    ... 69 more

I can see that the class is there in the jar. I think it is due to some jboss module classpath issue... asking for suggestions.

P.S. : I'm not using maven. Using at to build.

Foi útil?

Solução

You are facing the same problem as described in this answer.

In your specific case, the Hibernate JARs are loaded by a classloader that is an ancestor of the classloader that loads hibernate-ehcache-4.2.8.Final.jar. Thus these classes cannot see org.hibernate.cache.ehcache.*.

The solution would be to create a module for EHCache and use that module, instead of including the jar in WEB-INF/lib.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top