首页 > 解决方案 > java.lang.NoSuchMethodError: org.hibernate.StatelessSession.createQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;

问题描述

我一直在将我的框架(spring-ws、spring、spring-batch、hibernate)升级到最新版本。

 compile group: 'org.springframework.ws', name: 'spring-ws-core', version: '3.0.4.RELEASE'
compile group: 'org.springframework', name: 'spring-context', version: '5.1.1.RELEASE'
compile group: 'org.springframework', name: 'spring-context-support', version: '5.1.1.RELEASE'
compile group: 'org.springframework', name: 'spring-tx', version: '5.1.1.RELEASE'
compile group: 'org.springframework', name: 'spring-orm', version: '5.1.1.RELEASE'
compile group: 'org.springframework', name: 'spring-web', version: '5.1.1.RELEASE'
compile group: 'org.springframework.batch', name: 'spring-batch-core', version: '4.0.1.RELEASE'
compile group: 'org.springframework.batch', name: 'spring-batch-infrastructure', version: '4.0.1.RELEASE'
compile group: 'org.hibernate', name: 'hibernate-core', version: '5.3.6.Final'

一切似乎都工作正常,除了当我执行弹簧批处理作业时,我收到以下错误

java.lang.NoSuchMethodError: org.hibernate.StatelessSession.createQuery(Ljava/lang/String;)Lorg/hibernate/query/Query;
at org.springframework.batch.item.database.HibernateItemReaderHelper.createQuery(HibernateItemReaderHelper.java:148)
at org.springframework.batch.item.database.HibernateItemReaderHelper.getForwardOnlyCursor(HibernateItemReaderHelper.java:122)
at org.springframework.batch.item.database.HibernateCursorItemReader.doOpen(HibernateCursorItemReader.java:185)
at org.springframework.batch.item.support.AbstractItemCountingItemStreamItemReader.open(AbstractItemCountingItemStreamItemReader.java:146)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:343)
at org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.doProceed(DelegatingIntroductionInterceptor.java:136)
at org.springframework.aop.support.DelegatingIntroductionInterceptor.invoke(DelegatingIntroductionInterceptor.java:124)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212)
at com.sun.proxy.$Proxy50.open(Unknown Source)
at org.springframework.batch.item.support.CompositeItemStream.open(CompositeItemStream.java:103)
at org.springframework.batch.core.step.tasklet.TaskletStep.open(TaskletStep.java:310)
at org.springframework.batch.core.step.AbstractStep.execute(AbstractStep.java:197)
at org.springframework.batch.core.job.SimpleStepHandler.handleStep(SimpleStepHandler.java:148)
at org.springframework.batch.core.job.flow.JobFlowExecutor.executeStep(JobFlowExecutor.java:66)
at org.springframework.batch.core.job.flow.support.state.StepState.handle(StepState.java:67)
at org.springframework.batch.core.job.flow.support.SimpleFlow.resume(SimpleFlow.java:169)
at org.springframework.batch.core.job.flow.support.SimpleFlow.start(SimpleFlow.java:144)
at org.springframework.batch.core.job.flow.FlowJob.doExecute(FlowJob.java:136)
at org.springframework.batch.core.job.AbstractJob.execute(AbstractJob.java:308)
at org.springframework.batch.core.launch.support.SimpleJobLauncher$1.run(SimpleJobLauncher.java:141)
at java.lang.Thread.run(Thread.java:748)

我看到 HibernateItemReaderHelper 调用了 createQuery 方法,在这个方法中调用了 StatelessSession 的 createQuery 方法。

HibernateItemReaderHelper.creatQuery 返回一个 org.hibernate.query.Query 的对象;StatelessSession.createQuery 返回一个 org.hibernate.Query 的对象

我认为这是问题所在,但我该如何解决呢?请帮忙

标签: hibernatespring-batch

解决方案


Spring Batch Core 4.0.1.RELEASE似乎与Hibernate 5.2.12.Final兼容, 从它的标签 build.gradle 依赖文件中可以看出,所以试试看,而不是你的显式版本5.3.6.Final


推荐阅读