当前位置: 首页 > 面试题库 >

升级到Hibernate 5时,SessionFactoryImpl中的AbstractMethodError

章绪
2023-03-14
问题内容

我们正在使用Spring ORM 4.2.1.RELEASE通过JPA与Hibernate进行交互。Hibernate
4.3.11.Final一切正常,但是当我们尝试升级到Hibernate
5时,在构造SessionFactory时会出现AbstractMethodError中断。

根据发行说明,Spring
4.2.1确实支持Hibernate5。检查Maven依赖树没有显示任何重复或过时的Hibernate或Spring版本。报告的特定行(https://github.com/hibernate/hibernate-
orm/blob/master/hibernate-
core/src/main/java/org/hibernate/internal/SessionFactoryImpl.java第278行)正在迭代hibernate集成器,但是我们不使用任何集成器,因此,集成器列表在逻辑上应为空(因此不能进行迭代)。

有谁知道这是spring的错误(或缺乏支持),还是我们做错了?

从应用程序日志中提取:

2015-09-08 13:17:45,452 [main] INFO  org.springframework.test.context.support.DefaultTestContextBootstrapper - Using TestExecutionListeners: [org.springframework.test.context.web.ServletTestExecutionListener@20f0461e, org.springframework.test.context.support.DirtiesContextBeforeModesTestExecutionListener@7e8b6c76, org.springframework.test.context.support.DependencyInjectionTestExecutionListener@737df7e1, org.springframework.test.context.support.DirtiesContextTestExecutionListener@531d1003, org.springframework.test.context.transaction.TransactionalTestExecutionListener@19065f96, org.springframework.test.context.jdbc.SqlScriptsTestExecutionListener@716d7daf]
2015-09-08 13:17:45,460 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [dataContext.xml]
2015-09-08 13:17:45,689 [main] INFO  org.springframework.beans.factory.xml.XmlBeanDefinitionReader - Loading XML bean definitions from class path resource [systemContext.xml]
2015-09-08 13:17:45,779 [main] INFO  org.springframework.context.support.GenericApplicationContext - Refreshing org.springframework.context.support.GenericApplicationContext@4b56a656: startup date [Tue Sep 08 13:17:45 AEST 2015]; root of context hierarchy
2015-09-08 13:17:45,846 [main] INFO  org.springframework.context.support.PropertySourcesPlaceholderConfigurer - Loading properties file from class path resource [application.properties]
2015-09-08 13:17:45,900 [MLog-Init-Reporter] INFO  com.mchange.v2.log.MLog - MLog clients using slf4j logging.
2015-09-08 13:17:45,921 [main] INFO  com.mchange.v2.c3p0.C3P0Registry - Initializing c3p0-0.9.5.1 [built 16-June-2015 00:06:36 -0700; debug? true; trace: 10]
2015-09-08 13:17:46,046 [main] INFO  org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean - Building JPA container EntityManagerFactory for persistence unit 'default'
2015-09-08 13:17:46,060 [main] INFO  org.hibernate.jpa.internal.util.LogHelper - HHH000204: Processing PersistenceUnitInfo [
    name: default
    ...]
2015-09-08 13:17:46,136 [main] INFO  org.hibernate.Version - HHH000412: Hibernate Core {5.0.1.Final}
2015-09-08 13:17:46,137 [main] INFO  org.hibernate.cfg.Environment - HHH000206: hibernate.properties not found
2015-09-08 13:17:46,138 [main] INFO  org.hibernate.cfg.Environment - HHH000021: Bytecode provider name : javassist
2015-09-08 13:17:46,166 [main] INFO  org.hibernate.annotations.common.Version - HCANN000001: Hibernate Commons Annotations {5.0.0.Final}
2015-09-08 13:17:46,274 [main] INFO  com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource - Initializing c3p0 pool... com.mchange.v2.c3p0.ComboPooledDataSource [ acquireIncrement -> 3, acquireRetryAttempts -> 30, acquireRetryDelay -> 1000, autoCommitOnClose -> false, automaticTestTable -> null, breakAfterAcquireFailure -> false, checkoutTimeout -> 0, connectionCustomizerClassName -> null, connectionTesterClassName -> com.mchange.v2.c3p0.impl.DefaultConnectionTester, contextClassLoaderSource -> caller, dataSourceName -> z8kfsx9b1bfny2k11h75wx|4aa092d5, debugUnreturnedConnectionStackTraces -> false, description -> null, driverClass -> org.hsqldb.jdbcDriver, extensions -> {}, factoryClassLocation -> null, forceIgnoreUnresolvedTransactions -> false, forceSynchronousCheckins -> false, forceUseNamedDriverClass -> false, identityToken -> z8kfsx9b1bfny2k11h75wx|4aa092d5, idleConnectionTestPeriod -> 30, initialPoolSize -> 3, jdbcUrl -> jdbc:hsqldb:mem:testDB, maxAdministrativeTaskTime -> 0, maxConnectionAge -> 0, maxIdleTime -> 0, maxIdleTimeExcessConnections -> 0, maxPoolSize -> 15, maxStatements -> 0, maxStatementsPerConnection -> 0, minPoolSize -> 3, numHelperThreads -> 3, preferredTestQuery -> null, privilegeSpawnedThreads -> false, properties -> {user=******, password=******}, propertyCycle -> 0, statementCacheNumDeferredCloseThreads -> 0, testConnectionOnCheckin -> true, testConnectionOnCheckout -> true, unreturnedConnectionTimeout -> 0, userOverrides -> {}, usesTraditionalReflectiveProxies -> false ]
2015-09-08 13:17:46,396 [main] INFO  org.hibernate.dialect.Dialect - HHH000400: Using dialect: org.hibernate.dialect.HSQLDialect
2015-09-08 13:17:46,429 [main] INFO  org.hibernate.engine.jdbc.env.internal.LobCreatorBuilderImpl - HHH000423: Disabling contextual LOB creation as JDBC driver reported JDBC version [3] less than 4
2015-09-08 13:17:46,592 [main] WARN  org.springframework.context.support.GenericApplicationContext - Exception encountered during context initialization - cancelling refresh attempt
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'entityManagerFactory' defined in class path resource [dataContext.xml]: Invocation of init method failed; nested exception is java.lang.AbstractMethodError
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1578) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:545) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:305) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:301) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:196) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1045) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.finishBeanFactoryInitialization(AbstractApplicationContext.java:824) ~[spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:537) [spring-context-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:125) [spring-test-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    ... rows deleted
Caused by: java.lang.AbstractMethodError
    at org.hibernate.internal.SessionFactoryImpl.<init>(SessionFactoryImpl.java:278) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final]
    at org.hibernate.boot.internal.SessionFactoryBuilderImpl.build(SessionFactoryBuilderImpl.java:444) ~[hibernate-core-5.0.1.Final.jar:5.0.1.Final]
    at org.hibernate.jpa.boot.internal.EntityManagerFactoryBuilderImpl.build(EntityManagerFactoryBuilderImpl.java:802) ~[hibernate-entitymanager-5.0.1.Final.jar:5.0.1.Final]
    at org.springframework.orm.jpa.vendor.SpringHibernateJpaPersistenceProvider.createContainerEntityManagerFactory(SpringHibernateJpaPersistenceProvider.java:60) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean.createNativeEntityManagerFactory(LocalContainerEntityManagerFactoryBean.java:343) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.orm.jpa.AbstractEntityManagerFactoryBean.afterPropertiesSet(AbstractEntityManagerFactoryBean.java:318) ~[spring-orm-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1637) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.initializeBean(AbstractAutowireCapableBeanFactory.java:1574) ~[spring-beans-4.2.1.RELEASE.jar:4.2.1.RELEASE]
    ... 41 more

从Spring上下文中提取:

<bean id="jpaVendorAdapter" class="org.springframework.orm.jpa.vendor.HibernateJpaVendorAdapter"/>

<bean id="entityManagerFactory" class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean">
    <property name="dataSource" ref="dataSource"/>
    <property name="jpaVendorAdapter" ref="jpaVendorAdapter"/>
    <property name="packagesToScan" value="au.gov.qld.ssq.cofa.domain"/>
    <property name="jpaPropertyMap">
        <map>
            <entry key="hibernate.dialect" value="${hibernate.dialect}"/>
            <entry key="hibernate.show_sql" value="${hibernate.show_sql}"/>
            <entry key="hibernate.hbm2ddl.auto" value="${hibernate.hbm2ddl.auto}"/>
        </map>
    </property>
</bean>

问题答案:

此错误与Spring无关。您的类路径中有一个与Hibernate
5不兼容的集成器。这些是通过ServiceRegistry检测到的。

一个常见的问题是Jadira Usertype的较旧版本与Hibernate 5不兼容。如果您的类路径中的Jadira
User类型为5.0.0之前的版本,则会出现此异常。如果不是这种情况,并且您不确定哪个库存在问题,请在SessionFactoryImpl的第278行上放置一个断点,并检查导致异常的Integrator的类。



 类似资料:
  • 我们使用Spring ORM4.2.1.RELEASE通过JPA与HiberNate交互。HiberNate 4.3.11一切正常。最后,但是当我们尝试升级到HiberNate 5时,它在构建SessionWorks时中断了。 根据发行说明,Spring 4.2.1确实支持Hibernate 5。检查Maven依赖树没有显示Hibernate或Spring的任何重复或过时版本。报告的特定行(htt

  • 我一直在推迟从已弃用的表单api升级到@angle/form中的新表单api。我刚刚升级到RC6,现在也想开始使用@angle/form。 文档在这一点上非常稀缺,我很快就被卡住了。 这是我的工作形式: 在与此模板关联的组件上,FORM_DIRECTIVES是在组件的“DIRECTIVES”属性中指定的,这就是提供ngFormControl指令等的原因... 如果我理解正确的话,Control和C

  • 问题内容: 最近从BC 1.34升级到1.45。我正在使用以下代码解码一些先前编码的数据: 使用BC 1.45时,出现以下异常: 编辑:有关此问题的更多信息。我正在使用以下内容从密码短语生成原始密钥: 我发现这导致BC 1.34与1.45的两个不同值。 它也可能与BouncyCastle不相关(我正在Android 2.3上进行测试) 问题答案: 看起来问题在于SecureRandom无法跨Fro

  • 我应该将我的项目log4j升级到log4j2。所以我删除了log4j依赖项并添加了log4j2。一些项目工作良好,但有一个项目出现错误,如下所示: 我使用了mvn dependency:tree命令,试图找到依赖项之间的冲突,并且试图排除可能相关的每个子库,但仍然得到相同的错误。 依赖项: log4j2.properties:

  • 我从19.10升级到Ubuntu 20.04,现在我不能使用pip。 Python已安装: 但如果我试着检查pip,我会得到: 我迷路了。谢谢你的帮助 使现代化 我使用venv创建虚拟环境。当没有激活venv时,我可以使用pip3: 但是如果我激活一个venv,它就不起作用了: 感谢您的建议和持续的帮助。 使现代化 我尝试删除venv并创建一个新的venv,但似乎我需要pip工作才能做到这一点:

  • FIS 以下统称为 FIS2 简介 FIS3相对FIS2来说接口改动较大,并不是不考虑版本上的兼容,而是不愿意做简单的小修小补,希望从整体的角度打造一个易用性和可扩展性达到一个全新高度的工具。FIS2 与FIS3将并行维护,并且绝大部分插件是兼容的。 功能升级点简介 RoadMap目录定制更简单 FIS2中roadmap是最先匹配生效的,如果想覆盖解决方案的默认配置比较麻烦。FIS3中使用了类似c