Hibernate 5.3 Spring 5,Ehcache 3.5.2,jdk 10,Hibernate 说 "Cache provider not started"
Hibernate 5.3 Spring 5, Ehcache 3.5.2, jdk 10, Hibernate says "Cache provider not started"
...我的问题是,有了这个配置,我需要 "start" ehcache 吗?如果是,如何?这是一个通过库依赖项工作的迷宫,例如需要 hibernate-ehcache 和 ehcache 吗?需要 hibernate-jcache 吗?这是调试 3 天后 tomcat 9 标准输出的最终错误:
... 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
关键配置文件:
ivy.xml(节选):
<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(摘录)
<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(全部)
<?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>
我不确定在 Hibernate 中创建问题是个好主意。这很可能是您这边的配置问题。
我要说的第一件事是 hibernate-ehcache
不应该存在。这是用于Ehcache 2。不是JCache+Ehcache3。
那么,能否请您尝试将 jcache.xml
重命名为 ehcache.xml
?
最后,不,你应该不需要启动提供的。它应该自己开始。
Henri 说得对,我不需要 hibernate-ehcache。但是不需要将 jcache.xml 重命名为 ehcache.xml。
简而言之,解决我的错误的方法是将 jcache.xml 资源添加到我的 ant 构建中,因为它没有被部署。话虽如此,对于可能有此错误的其他人来说,对于 hibernate 5.3,spring 5,ehcache 3.5.2,jdk 10,存在如此多的可能性和缺乏明确的简单愚蠢配置, tomcat 9,你唯一的希望(除了运气,它确实有效)是将 tomcat 置于调试模式,附加 eclipse,将 hibernate-core 源添加到 eclipse 项目,在有问题的休眠 class/method 并查看在您的特定配置中什么不是 available/expected。
对于其他试图使这项工作有效的人来说,奇怪的是,我确实需要 spring-boot-starter-cache,如果没有它,我的 spring 休眠配置的 none 会被读取。我是 13 岁的 Spring 2.5 人,所以我还没有理解 spring 引导是什么。它应该是 "opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss"。但它似乎也是一个 runtime/embedded tomcat,所以不管怎样,我确信它有时非常有用,而且相当不确定并且使其他人感到困惑....
...我的问题是,有了这个配置,我需要 "start" ehcache 吗?如果是,如何?这是一个通过库依赖项工作的迷宫,例如需要 hibernate-ehcache 和 ehcache 吗?需要 hibernate-jcache 吗?这是调试 3 天后 tomcat 9 标准输出的最终错误:
... 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
关键配置文件:
ivy.xml(节选):
<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(摘录)
<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(全部)
<?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>
我不确定在 Hibernate 中创建问题是个好主意。这很可能是您这边的配置问题。
我要说的第一件事是 hibernate-ehcache
不应该存在。这是用于Ehcache 2。不是JCache+Ehcache3。
那么,能否请您尝试将 jcache.xml
重命名为 ehcache.xml
?
最后,不,你应该不需要启动提供的。它应该自己开始。
Henri 说得对,我不需要 hibernate-ehcache。但是不需要将 jcache.xml 重命名为 ehcache.xml。
简而言之,解决我的错误的方法是将 jcache.xml 资源添加到我的 ant 构建中,因为它没有被部署。话虽如此,对于可能有此错误的其他人来说,对于 hibernate 5.3,spring 5,ehcache 3.5.2,jdk 10,存在如此多的可能性和缺乏明确的简单愚蠢配置, tomcat 9,你唯一的希望(除了运气,它确实有效)是将 tomcat 置于调试模式,附加 eclipse,将 hibernate-core 源添加到 eclipse 项目,在有问题的休眠 class/method 并查看在您的特定配置中什么不是 available/expected。
对于其他试图使这项工作有效的人来说,奇怪的是,我确实需要 spring-boot-starter-cache,如果没有它,我的 spring 休眠配置的 none 会被读取。我是 13 岁的 Spring 2.5 人,所以我还没有理解 spring 引导是什么。它应该是 "opinionated view of the Spring platform and third-party libraries so you can get started with minimum fuss"。但它似乎也是一个 runtime/embedded tomcat,所以不管怎样,我确信它有时非常有用,而且相当不确定并且使其他人感到困惑....