*Error using Second Level Cache on OSGi/Karaf/hibernate/Jcache/ehcache*
*Using:*
* Hibernate 5.4.2 * Karaf 4.2.5 * Ehcache 3 * Jcache 1.1.1
A bundle application on OSGi environment using karaf works fine if the second level cache is off, but if the property *hibernate.cache.use_second_level_cache* is true there is an
*Caused by: java.lang.ClassNotFoundException: org.ehcache.jsr107.EhcacheCachingProvider*
Ehcache bundle is exporting EhcacheCachingProvider but is not accessible by hibernate classloader
``` service; [javax.cache.spi.CachingProvider] with properties: component.id = 20 component.name = org.ehcache.jsr107.EhcacheCachingProvider service.bundleid = 97 service.id = 170 service.scope = bundle ```
The problem is in class: ``` org.hibernate.cache.jcache.internal.JCacheRegionFactory trying to get a CachingProvider ```
In OSGI environments, the classloader used is not the org.hibernate.orm.jcache, instead is used *sun.misc.Launcher$AppClassLoader*
So, a java.lang.ClassNotFoundException: org.ehcache.jsr107.EhcacheCachingProvider is throwed by hibernate-jcache.
a test case: https://github.com/klebeer/karaf-hibernate2Lcache-bug |
|