[英]SingletonEhCacheRegionFactory is no longer available when upgrading from Hibernate 5.2 to 5.3
A project I work on is currently using Hibernate version 5.2.15.Final.我从事的一个项目目前正在使用 Hibernate 版本 5.2.15.Final。 When configuring the second-level cache, the project has been using
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
as the value for hibernate.cache.region.factory_class
.在配置二级缓存时,项目一直使用
org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
作为hibernate.cache.region.factory_class
的值。
When I change the Hibernate version to 5.3.12.Final, SingletonEhCacheRegionFactory
is no longer in that package.当我将 Hibernate 版本更改为 5.3.12.Final 时,
SingletonEhCacheRegionFactory
不再在该 package 中。 A class with that same name is available in the net.sf.ehcache.hibernate
package, and I can use that with no compilation errors.具有相同名称的 class 可在
net.sf.ehcache.hibernate
package 中使用,我可以使用它而不会出现编译错误。 But if I run it I get an error when it tries to build a session:但是,如果我运行它,当它尝试构建 session 时会出现错误:
org.hibernate.service.spi.ServiceException: Unable to create requested service [org.hibernate.cache.spi.RegionFactory]
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:275)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.initializeService(AbstractServiceRegistryImpl.java:237)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.getService(AbstractServiceRegistryImpl.java:214)
at org.hibernate.boot.internal.MetadataBuilderImpl$MetadataBuildingOptionsImpl.<init>(MetadataBuilderImpl.java:688)
at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:123)
at org.hibernate.boot.internal.MetadataBuilderImpl.<init>(MetadataBuilderImpl.java:93)
If I dig deeper into the stack trace, the real error seems to be this:如果我深入研究堆栈跟踪,真正的错误似乎是:
Caused by: org.hibernate.boot.registry.selector.spi.StrategySelectionException: Unable to resolve name [net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory] as strategy [org.hibernate.cache.spi.RegionFactory]
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:133)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:212)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.resolveStrategy(StrategySelectorImpl.java:169)
at org.hibernate.cache.internal.RegionFactoryInitiator.resolveRegionFactory(RegionFactoryInitiator.java:93)
at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:47)
at org.hibernate.cache.internal.RegionFactoryInitiator.initiateService(RegionFactoryInitiator.java:32)
at org.hibernate.boot.registry.internal.StandardServiceRegistryImpl.initiateService(StandardServiceRegistryImpl.java:94)
at org.hibernate.service.internal.AbstractServiceRegistryImpl.createService(AbstractServiceRegistryImpl.java:263)
... 64 more
Caused by: org.hibernate.boot.registry.classloading.spi.ClassLoadingException: Unable to load class [net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory]
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:137)
at org.hibernate.boot.registry.selector.internal.StrategySelectorImpl.selectStrategyImplementor(StrategySelectorImpl.java:129)
... 71 more
Caused by: java.lang.NoClassDefFoundError: org/hibernate/cache/QueryResultsRegion
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:374)
at org.hibernate.boot.registry.classloading.internal.ClassLoaderServiceImpl.classForName(ClassLoaderServiceImpl.java:131)
... 72 more
Caused by: java.lang.ClassNotFoundException: org.hibernate.cache.QueryResultsRegion
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:190)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:499)
... 75 more
Here's what my pom.xml dependencies look like:这是我的 pom.xml 依赖项的样子:
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.3.12.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-ehcache</artifactId>
<version>5.3.12.Final</version>
</dependency>
<dependency>
<groupId>net.sf.ehcache</groupId>
<artifactId>ehcache-core</artifactId>
<version>2.6.11</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-c3p0</artifactId>
<version>5.3.12.Final</version>
</dependency>
Okay, I think I figured out the problem.好吧,我想我找到了问题所在。 Previously my code had been fetching the full class name and path by doing:
以前我的代码通过执行以下操作获取完整的 class 名称和路径:
SingletonEhCacheRegionFactory.class.getCanonicalName()
But in Hibernate 5.3 the class had been moved to an internal package, which is why I could no longer find it.但在 Hibernate 5.3 中,class 已被移至内部 package,这就是我找不到它的原因。 If I used a hardcoded string with the old package name (
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
), I no longer get that exception.如果我使用带有旧 package 名称(
"org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory"
)的硬编码字符串,我不再得到那个异常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.