Reputation: 2310
...my question is, with this configuration, do i need to "start" ehcache? if yes, how? it is a maze working though the libs dependencies, e.g. need hibernate-ehcache and ehcache? need hibernate-jcache? Here is the final error on tomcat 9 standard out after 3 days of debug:
... 93 common frames omitted
aused by: java.lang.IllegalStateException: Cache provider not started
at org.hibernate.cache.spi.AbstractRegionFactory.verifyStarted(AbstractRegionFactory.java:42)
at org.hibernate.cache.spi.support.RegionFactoryTemplate.buildTimestampsRegion(RegionFactoryTemplate.java:66)
at org.hibernate.cache.internal.EnabledCaching.<init>(EnabledCaching.java:80)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:33)
at org.hibernate.engine.spi.CacheInitiator.initiateService(CacheInitiator.java:24)
at org.hibernate.service.spi.SessionFactoryServiceInitiator.initiateService(SessionFactoryServiceInitiator.java:
0)
at org.hibernate.service.internal.SessionFactoryServiceRegistryImpl.initiateService(SessionFactoryServiceRegistr
Impl.java:68)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263
key config files:
ivy.xml (excerpt):
<dependency org="org.hibernate" name="hibernate-core" rev="5.3.0.Final">
</dependency>
<dependency org="org.hibernate" name="hibernate-jcache" rev="5.3.0.Final" />
<dependency org="org.hibernate" name="hibernate-ehcache"
rev="5.3.0.Final" />
<dependency org="org.springframework.boot" name="spring-boot-starter-cache"
rev="2.0.2.RELEASE" />
<dependency org="org.ehcache" name="ehcache" rev="3.5.2" />
<dependency org="org.springframework" name="spring-orm" rev="5.0.6.RELEASE" />
<dependency org="org.springframework" name="spring-core"
rev="5.0.6.RELEASE" />
Spring hibernateContext.xml (excerpt)
<property name="hibernateProperties">
<props>
<prop key="hibernate.c3p0.acquire_increment">5</prop>
<prop key="hibernate.c3p0.idle_test_period">100</prop>
<prop key="hibernate.c3p0.max_size">20</prop>
<prop key="hibernate.c3p0.max_statements">50</prop>
<prop key="hibernate.c3p0.min_size">5</prop>
<prop key="hibernate.c3p0.timeout">300</prop>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.show_sql">false</prop>
<prop key="hibernate.format_sql">false</prop>
<prop key="hibernate.use_sql_comments">false</prop>
<!-- <prop key="hibernate.enable_lazy_load_no_trans">true</prop> -->
<!-- ehcache settings -->
<prop key="hibernate.cache.use_query_cache">true</prop>
<prop key="hibernate.cache.region.factory_class">org.hibernate.cache.jcache.JCacheRegionFactory</prop>
<prop key="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</prop>
<prop key="hibernate.cache.use_second_level_cache">true</prop>
<prop key="hibernate.cache.default_cache_concurrency_strategy">read-write</prop>
<prop key="hibernate.javax.cache.uri">classpath:jcache.xml</prop>
</props>
</property>
</bean>
jcache.xml (all of it)
<?xml version="1.0" encoding="UTF-8"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://www.ehcache.org/v3" xmlns:jsr107="http://www.ehcache.org/v3/jsr107"
xsi:schemaLocation="
http://www.ehcache.org/v3
http://www.ehcache.org/schema/ehcache-core.xsd
http://www.ehcache.org/v3/jsr107
http://www.ehcache.org/schema/ehcache-107-ext.xsd">
<!-- https://hibernate.atlassian.net/browse/HHH-12531 -->
<service>
<jsr107:defaults enable-management="true" enable-statistics="true" default-template="default" />
</service>
<cache alias="org.hibernate.cache.spi.QueryResultsRegion">
<expiry>
<tti unit="seconds">300</tti>
</expiry>
<heap>1024</heap>
</cache>
<cache alias="org.hibernate.cache.spi.TimestampsRegion">
<expiry>
<none />
</expiry>
<heap>4096</heap>
</cache>
<cache-template name="default">
<expiry>
<tti unit="seconds">300</tti>
</expiry>
<heap>1024</heap>
</cache-template>
created a hibernate issue too https://hibernate.atlassian.net/browse/HHH-12635
Upvotes: 1
Views: 7659
Reputation: 4052
I had the same issue. Checking only this message: Cache provider not started did not really helped me. I had to throw the entire exception to get more detail. In my case after throwing the entire exception stack, I had couple of errors:
here is my settup:
Pom.xml
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>6.0.0.Alpha7</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-jcache</artifactId>
<version>6.4.1.Final</version>
</dependency>
<dependency>
<groupId>org.ehcache</groupId>
<artifactId>ehcache</artifactId>
<version>3.10.8</version>
<classifier>jakarta</classifier>
</dependency>
hibernate.cfg.xml
<property name="hibernate.cache.use_second_level_cache">true</property>
<property name="hibernate.cache.region.factory_class">jcache</property>
<property name="hibernate.cache.use_query_cache">true</property>
<property name="hibernate.javax.cache.provider">org.ehcache.jsr107.EhcacheCachingProvider</property>
<property name="hibernate.javax.cache.uri">ehcache.xml</property>
ehcache.xml
<?xml version="1.0" encoding="UTF-8"?>
<!-- https://hibernate.atlassian.net/browse/HHH-12531 -->
<service>
<jsr107:defaults enable-management="true" enable-statistics="true" default-template="default" />
</service>
<cache alias="default-query-results-region">
<expiry><ttl unit="minutes">60</ttl></expiry>
<heap unit="entries">1000</heap>
</cache>
<cache alias="default-update-timestamps-region">
<expiry><none/></expiry>
<heap unit="entries">1000</heap>
</cache>
<cache-template name="default">
<expiry>
<!-- We can not use tti and ttl at the same time -->
<!-- TimeToIdle : the object will be invalidated if it hasn't been requested for x seconds-->
<!-- TimeToLive : the object will be removed from cache after x seconds, even if it has been requested few milliseconds in the xth second of its short life-->
<tti unit="seconds">120</tti>
</expiry>
<heap>1024</heap>
</cache-template>
<cache alias="supportedCurrency">
<key-type>java.lang.Long</key-type>
<value-type>com.coder.hms.entities.SupportedCurrency</value-type>
<expiry>
<!-- TimeToLive : the object will be removed from cache after 120 seconds, even if it has been requested few milliseconds in the 120th second of its short life-->
<ttl>120</ttl>
</expiry>
<heap unit="entries">10000</heap>
</cache>
Upvotes: 0
Reputation: 2310
Henri was right that I did not need hibernate-ehcache. But renaming jcache.xml to ehcache.xml was not required.
In short the fix to my error was to add the jcache.xml resource to my ant build, because it was not getting deployed. With that said, for others who may have this error, there is such a maze of possibilities and lack of clear simple-stupid config for hibernate 5.3, spring 5, ehcache 3.5.2, jdk 10, tomcat 9, your only hope (other than dumb luck, which does work) is to put tomcat in debug mode, attach eclipse, add the hibernate-core source to an eclipse project, set a breakpoint in the offending hibernate class/method and see what is not available/expected in your particular configuration.
Also for others trying to make this work, strange, I do need spring-boot-starter-cache, without it none of my spring hibernate config is read. I am a Spring 2.5 guy of 13 years, so i have yet to understand what spring boot is. it is suppose to be an "opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss". but it also seems to be a runtime/embedded tomcat, so whatever, i am sure that it is quite useful sometimes and quite undefined and confusing others....
Upvotes: 0
Reputation: 5731
I'm not sure creating an issue in Hibernate was a good idea. This is most probably a configuration issue on your side.
The first thing I can say is that hibernate-ehcache
should not be there. This is used for Ehcache 2. Not JCache+Ehcache3.
Then, can you please try to rename the jcache.xml
to ehcache.xml
?
Finally, no, you should not need to start the provided. It should start by itself.
Upvotes: 0