Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spring Batch fails to get "nextval" from H2 v2.x #4045

Closed
sergeykad opened this issue Jan 10, 2022 · 3 comments
Closed

Spring Batch fails to get "nextval" from H2 v2.x #4045

sergeykad opened this issue Jan 10, 2022 · 3 comments
Labels
for: external-project Issues that should be opened against other Spring projects type: bug

Comments

@sergeykad
Copy link

sergeykad commented Jan 10, 2022

Bug description
Launching step fails with the following error:

Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "BATCH_JOB_SEQ.NEXTVAL" not found; SQL statement:
select BATCH_JOB_SEQ.nextval from dual [42122-206]
org.springframework.dao.DataAccessResourceFailureException: Could not obtain sequence value; nested exception is org.h2.jdbc.JdbcSQLSyntaxErrorException: Column "BATCH_JOB_SEQ.NEXTVAL" not found; SQL statement:
select BATCH_JOB_SEQ.nextval from dual [42122-206]
	at app//org.springframework.jdbc.support.incrementer.AbstractSequenceMaxValueIncrementer.getNextKey(AbstractSequenceMaxValueIncrementer.java:79)
	at app//org.springframework.jdbc.support.incrementer.AbstractDataFieldMaxValueIncrementer.nextLongValue(AbstractDataFieldMaxValueIncrementer.java:128)
	at app//org.springframework.batch.core.repository.dao.JdbcJobInstanceDao.createJobInstance(JdbcJobInstanceDao.java:113)
	at app//org.springframework.batch.core.repository.support.SimpleJobRepository.createJobExecution(SimpleJobRepository.java:148)
	at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:564)
	at app//org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at app//org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123)
	at app//org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388)
	at app//org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.batch.core.repository.support.AbstractJobRepositoryFactoryBean$1.invoke(AbstractJobRepositoryFactoryBean.java:181)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at app//com.sun.proxy.$Proxy163.createJobExecution(Unknown Source)
	at app//org.springframework.batch.core.launch.support.SimpleJobLauncher.run(SimpleJobLauncher.java:137)
	at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at [email protected]/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:64)
	at [email protected]/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at [email protected]/java.lang.reflect.Method.invoke(Method.java:564)
	at app//org.springframework.aop.support.AopUtils.invokeJoinpointUsingReflection(AopUtils.java:344)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.invokeJoinpoint(ReflectiveMethodInvocation.java:198)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163)
	at app//org.springframework.batch.core.configuration.annotation.SimpleBatchConfiguration$PassthruAdvice.invoke(SimpleBatchConfiguration.java:128)
	at app//org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186)
	at app//org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215)
	at app//com.sun.proxy.$Proxy166.run(Unknown Source)
	at app//org.springframework.batch.test.StepRunner.launchJob(StepRunner.java:172)
	at app//org.springframework.batch.test.StepRunner.launchStep(StepRunner.java:161)
	at app//org.springframework.batch.test.JobLauncherTestUtils.launchStep(JobLauncherTestUtils.java:251)
	at app//org.springframework.batch.test.JobLauncherTestUtils.launchStep(JobLauncherTestUtils.java:225)

Environment
Spring Batch 4.3.3
Java 15
H2 2.0.206

Steps to reproduce
Run Spring Batch with H2 v2.x database

Expected behavior
Spring Batch works normally with H2 versions without RCE flaw (https://jfrog.com/blog/the-jndi-strikes-back-unauthenticated-rce-in-h2-database-console/)

Minimal Complete Reproducible example
Take this project as the base: https://github.com/spring-guides/gs-batch-processing/tree/main/complete
Perform the following modifications:

  1. Replace 'org.hsqldb:hsqldb' with 'com.h2database:h2:2.0.206' in build.gradle
  2. Extract /org/springframework/batch/core/schema-postgresql.sql from the spring-batch-core jar and put it under resources folder as schema.sql.

Build and run the application.

P.S. Using schema-h2.sql does not work. I assume it is a separate issue.

@sergeykad sergeykad added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Jan 10, 2022
@Jasper-Zhao-X
Copy link

I met similar issue, solved by spring-projects/spring-boot#29034

@sbrannen
Copy link
Member

This particular bug was fixed in Spring Framework 5.3.15.

@cppwfs
Copy link
Contributor

cppwfs commented Jan 31, 2022

Thank you for opening this issue.
This issue has been resolved in the current main branch here
It will be backported to the 4.3.5 release as discussed here
I will close, please re-open if you feel it was closed by mistake.

@cppwfs cppwfs closed this as completed Jan 31, 2022
@fmbenhassine fmbenhassine added for: external-project Issues that should be opened against other Spring projects and removed status: waiting-for-triage Issues that we did not analyse yet labels Apr 7, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
for: external-project Issues that should be opened against other Spring projects type: bug
Projects
None yet
Development

No branches or pull requests

5 participants