I try to migrate our application from Hibernate 5.2 with Ehcache 2 to Hibernate 5.3 with Jcache and Ehcache 3.
I have a problem to get Hibernate (EntityManagerFactory) started with enabled Jcache/Ehcache in my Tomcat webserver. The problem is: The configuration file ehcache.xml is not found.
I don’t know how to configure the location of this configuration file. Probably it’s a problem with the URI.The result is a (catched) javax.cache.CacheException: org.ehcache.xml.exceptions.XmlConfigurationException: Error parsing XML configuration at file:/META-INF/ehcache.xml in in AbstractRegionFactory.start().
These are my relevant JARs:
cache-api-1.0.0.jar
ehcache-3.5.2.jar
hibernate-commons-annotations-5.0.3.Final.jar
hibernate-core-5.3.0.Final.jar
hibernate-jcache-5.3.0.Final.jar
This is my configuration for the second level cache:
“hibernate.cache.region.factory_class”, “jcache”
“hibernate.javax.cache.provider”, “org.ehcache.jsr107.EhcacheCachingProvider”
“hibernate.javax.cache.uri”, “file:///META-INF/ehcache.xml” // tried many alternative values
The location of my ehcache.xml is
<TOMCAT_HOME>/webapps/myApp/WEB-INF/classes/META-INF/ehcache.xml
What is the correct value of the property “hibernate.javax.cache.uri”?
When I put this ehcache.xml in my root directory C: and configure “file:///ehcache.xml”, the configuration file is found and parsed and everything seems to work fine. But that is not the correct location…
Thank you Vlad, but the ehcache.xml is ok.
If I put the ehcache.xml to “C:” (windows) and set property “hibernate.javax.cache.uri” to “file:///ehcache.xml”, it works
I tried with “classpath://META-INF/ecache.xml”, in this case the result is a
javax.cache.CacheException: java.net.MalformedURLException: unknown protocol: classpath
I don’t like it that I have to use different classpath url syntaxes.
But it is still better then the TomcatURLStreamHandlerFactory workaround.
@vlad What do you think. Any chance to have the syntaxes aligned?
UPDATE
Everything I said above is true in our test environment.
As soon as the application is deployed to tomcat, the following Exception occurs:
Caused by: java.io.FileNotFoundException: Unable to load the resource [classpath://META-INF/ehcache-jsr107-config-hibernate.xml] using the thread context class loader or the current class’s class loader
at org.apache.catalina.webresources.ClasspathURLStreamHandler.openConnection(ClasspathURLStreamHandler.java:45)
So, it would be great if hibernate would also support the other classpath syntax.
For now, I will have to use the TomcatURLStreamHandlerFactory workaround again.