Skip to content

Spring Batch with Embedded database on Spring 3.0.5 throws error bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?] #4336

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

Closed
tirtawn opened this issue Mar 27, 2023 · 2 comments
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug

Comments

@tirtawn
Copy link

tirtawn commented Mar 27, 2023

Bug Description:
Create a new project with 3.0.5 with embedded H2 database and create a simple tasklet.

Run the jar file and Spring batch will throw out the error:
PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME from BATCH_JOB_INSTANCE where JOB_NAME = ? and JOB_KEY = ?]

The same project (while using jobBuilderFactory and stepBuilderFactory) on 2.7.7 will work fine.

Note: If you create the schema using org/springframework/batch/core/schema-h2.sql then the jar file will work.

Environment
Spring 3.0.5
Java 17
Maven

Steps to reproduce
Steps to reproduce the issue.
Attach the simple springdemo.zip - a very simple empty tasklet job to reproduce the issue.
Note: Creating the H2 database using file database and run the h2-schema.sql will fix the issue.
The same bug can be reproduced on different database e.g. PostGres.

Expected behavior
Expected that spring batch will create the tables on the fly when running the job (same behaviour as Spring 2.7.7.
Since I have put on:
application.properties
spring.batch.jdbc.initialize-schema=always

Minimal Complete Reproducible example
springdemo.zip is attached

Compiling and running the jar file should reproduce the error

Please provide a failing test or a minimal complete verifiable example that reproduces the issue.
Bug reports that are reproducible will take priority in resolution over reports that are not reproducible.
springdemo.zip

@tirtawn tirtawn added status: waiting-for-triage Issues that we did not analyse yet type: bug labels Mar 27, 2023
@hpoettker
Copy link
Contributor

Hi @tirtawn, in Spring Boot 3 the annotation @EnableBatchProcessing disables the auto-configuration for Spring Batch, which has not been the case in Spring Boot 2. Please try removing the annotation.

For more details, please have a look at the Spring Boot 3 migration guide here: Spring Batch Changes. Please also check the migration guide of Spring Batch 5.

@tirtawn
Copy link
Author

tirtawn commented Mar 27, 2023

Thanks for the document.
"@EnableBatchProcessing is now discouraged
Previously, @EnableBatchProcessing could be used to enable Spring Boot’s auto-configuration of Spring Batch. It is no longer required and should be removed from applications that want to use Boot’s auto-configuration. A bean that is annotated with @EnableBatchProcessing or that extends Batch’s DefaultBatchConfiguration can now be defined to tell the auto-configuration to back off, allowing the application to take complete control of how Batch is configured."

Got it, I have gotten used to this annotation. Now I know this is no longer necessary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage Issues that we did not analyse yet type: bug
Projects
None yet
Development

No branches or pull requests

2 participants