简体   繁体   English

从 Hibernate 5.2 升级到 5.3 时,SingletonEhCacheRegionFactory 不再可用

[英]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.

相关问题 invalidDataAccessApiUsageException - OUT/INOUT 参数不可用。 从 springboot 1.5.7 升级到 2.1.6 和 hibernate 5.3 - invalidDataAccessApiUsageException - OUT/INOUT Parameter is not available. Upgrading from springboot 1.5.7 to 2.1.6 and hibernate 5.3 当从hibernate 5.2迁移到5.3时,hibernate尝试使用一个奇怪的序列 - when migrating from hibernate 5.2 to 5.3, hibernate tries to use a weird sequence 从 5.2 升级到 Hibernate 5.3 后,Ear Deployment 使用 null 模块失败,我使用的是 wweblogic 12c 12.1.3 - Ear Deployment is failing with null module after upgrading to Hibernate 5.3 from 5.2, i am using wweblogic 12c 12.1.3 在 AWS 上从 MySQL 5.5 升级到 5.6 时 Hibernate 和日期的问题 - Problems with Hibernate and dates when upgrading from MySQL 5.5 to 5.6 on AWS 升级到Hibernate 5时,SessionFactoryImpl中的AbstractMethodError - AbstractMethodError in SessionFactoryImpl when upgrading to Hibernate 5 Hibernate 5.4.25 二级缓存和扩展 SingletonEhcacheRegionFactory class - Hibernate 5.4.25 second level cache and extending the SingletonEhcacheRegionFactory class addPlugInSingleRowFunction 将 Esper 版本从 5.3 升级到 8.3 中的问题 - Issue in addPlugInSingleRowFunction upgrading Esper version from 5.3 to 8.3 从itext5升级到itext5.2的问题 - issue with upgrading from itext5 to itext5.2 从IOException恢复:网络名称不再可用 - Recovering from IOException: network name no longer available java.lang.NoClassDefFoundError:org / hibernate / cache / spi / RegionFactory - 从spring 3升级到spring 4 - java.lang.NoClassDefFoundError: org/hibernate/cache/spi/RegionFactory - When upgrading from spring 3 to spring 4
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM