Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9138051
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T09:12:24+00:00 2026-06-17T09:12:24+00:00

I have a Spring Batch deployment in production, which was originally developed using an

  • 0

I have a Spring Batch deployment in production, which was originally developed using an H2 data source for the job repository. Everything is working fine with this initial effort, but we would like to replace H2 with a more traditional database as our use of Spring Batch expands. For better or for worse (it wasn’t completely my decision), I am moving to MySQL instead.

I have switched the data source for the job repository from H2 to MySQL, and changed the element to use “classpath:/org/springframework/batch/core/schema-mysql.sql“. When I run a batch job for the very first time, Spring Batch creates the repository tables and runs my job without issue.

However, subsequent executions fail… even though I am properly using a job incrementer, passing the “-next” parameter, and have seen it work fine with H2. When I set my logging to “debug” level, I see the following exception being through on subsequent executions:

org.springframework.dao.DuplicateKeyException: PreparedStatementCallback; SQL [INSERT into BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; 
Duplicate entry '1' for key 'PRIMARY'; 
nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '1' for key 'PRIMARY'

I’ve looked at the “schema-*.sql” scripts that Spring Batch uses to create its job repository tables. Other database types (e.g. H2, Oracle, Postgres, etc) create three sequences… BATCH_STEP_EXECUTION_SEQ, BATCH_JOB_EXECUTION_SEQ, and BATCH_JOB_SEQ. I am not a MySQL expert, but it looks like MySQL lacks support for sequences… because “schema-mysql.sql” includes these lines as an apparent workaround:

CREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT NOT NULL) ENGINE=MYISAM;
INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
CREATE TABLE BATCH_JOB_EXECUTION_SEQ (ID BIGINT NOT NULL) ENGINE=MYISAM;
INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
CREATE TABLE BATCH_JOB_SEQ (ID BIGINT NOT NULL) ENGINE=MYISAM;
INSERT INTO BATCH_JOB_SEQ values(0);

It seems obvious that MySQL’s handling of sequences and autoincrement values differs from other databases, and so presumably Spring Batch has to do something different to increment ID’s in its job repository tables. Are there some other MySQL-specific steps I need to take, of which I might not be aware? Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T09:12:24+00:00Added an answer on June 17, 2026 at 9:12 am

    The problem was that I was executing the classpath:/org/springframework/batch/core/schema-mysql.sql script with each job run.

    With H2, this is fine… and as long as the jdbc:initialize-database element includes the ignore-failures="ALL" attribute, you won’t really notice an issue.

    However, the MySQL-specific workaround for sequences is NOT something that you can execute repeatedly without Spring Batch getting messed up.

    I removed the jdbc:initialize-database element from my Spring Batch config, manually executed that classpath:/org/springframework/batch/core/schema-mysql.sql setup script one time in an empty database, and my job runs multiple invocations just fine.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

i have a spring batch job which needs to be scheduled at specific hour
I have a simple spring batch program which reads data from a INPUT file
I am working with the spring batch data loader . I have 15000 files
I have a spring batch application which loads multiple files into several data tables.
I have defined a Spring Batch job which runs once just fine. However it
I have a Spring Batch job which takes parameters, and the parameters are usually
I have created a spring-batch job. My reader class reads the data from the
I have a Spring Batch process which has following kind of code. <step id=step1
I am new to Spring Batch. I have following question. I am using Spring
I have a standalone testcase for spring batch to copy data form one table

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.