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

  • SEARCH
  • Home
  • 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 8764491
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:02:51+00:00 2026-06-13T16:02:51+00:00

I have defined a Spring Batch job which runs once just fine. However it

  • 0

I have defined a Spring Batch job which runs once just fine. However it is unable to run a second time due to a duplicate entry in the primary key for the JOB_INSTANCE_ID;

SEVERE: Job Terminated in error: PreparedStatementCallback; SQL [INSERT into    BATCH_JOB_INSTANCE(JOB_INSTANCE_ID, JOB_NAME, JOB_KEY, VERSION) values (?, ?, ?, ?)]; Duplicate entry '0' for key 'PRIMARY'; nested exception is com.mysql.jdbc.exceptions.jdbc4.MySQLIntegrityConstraintViolationException: Duplicate entry '0' for key 'PRIMARY'

I’ve read that this can be over-come by setting command line parameters on the job, e.g.

java -cp ${CLASSPATH} org.springframework.batch.core.launch.support.CommandLineJobRunner myJob.xml myJob date=20121025154016 -next

Whether I include the -next parameter or not, it will not run the job.

My Spring Batch configuration looks as follows (batch/launchContext.xml);

<?xml version="1.0" encoding="UTF-8"?>
<beans
    xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:batch="http://www.springframework.org/schema/batch"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:util="http://www.springframework.org/schema/util"
    xmlns:jdbc="http://springframework.org/schema/jdbc"
    xsi:schemaLocation="http://www.springframework.org/schema/jdbc     http://www.springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
    http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.5.xsd
    http://www.springframework.org/schema/batch http://www.springframework.org/schema/batch/spring-batch.xsd
http://springframework.org/schema/jdbc http://springframework.org/schema/jdbc/spring-jdbc.xsd
    http://www.springframework.org/schema/context 
http://www.springframework.org/schema/context/spring-context.xsd">

    <!-- Launch context: how to launch all of the jobs -->
    <!-- Expects a data source configuration file to be used, with a DataSource bean 
called "dataSource" -->

    <!-- The data source for the jobs status -->
    <import resource="dataSource.xml" />

    <bean
            id="jobRepository"                        
class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
            <property
                    name="dataSource"
                    ref="dataSource" />
            <property
                    name="databaseType"
                    value="MySQL" />
            <property
                    name="transactionManager"
                    ref="transactionManager"></property>
    </bean>

    <bean
            id="incrementer"
            class="org.springframework.batch.core.launch.support.RunIdIncrementer" />

    <bean
            id="jobLauncher"
            class="org.springframework.batch.core.launch.support.SimpleJobLauncher">
            <property
                    name="jobRepository"
                    ref="jobRepository" />
    </bean>

    <bean
            id="transactionManager"
            class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
            <property
                    name="dataSource"
                    ref="dataSource" />
    </bean>

    <bean
            id="jobExplorer"       
class="org.springframework.batch.core.explore.support.JobExplorerFactoryBean">
            <property
                    name="dataSource"
                    ref="dataSource" />
    </bean>

</beans>

And the job is like this (in the myJob.xml file)

....
<import resource="batch/launchContext.xml" />
...
    <batch:job
            id="myJob"
            job-repository="jobRepository"
            incrementer="incrementer">
            <batch:step id="step1">
                    <batch:tasklet transaction-manager="transactionManager">
                            <batch:chunk
                                    reader="myReader"
                                    processor="myProcessor"
                                    writer="myWriter"
                                    commit-interval="10" />
                    </batch:tasklet>
            </batch:step>
    </batch:job>

Ideally what I’d like is each run of the job to be persisted with the run date/time. Is there a way to configure the launcher to do this automatically?

  • 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-13T16:02:53+00:00Added an answer on June 13, 2026 at 4:02 pm

    I’d also placed this question on the official Spring Forums. And I eventually found my own answer (with a hint along the way);

    http://forum.springsource.org/showthread.php?131347-How-to-re-run-a-job&p=428484#post428484

    In short, the problem was that I’d deleted the value ‘0’ from these three tables;

    • BATCH_STEP_EXECUTION_SEQ
    • BATCH_JOB_EXECUTION_SEQ
    • BATCH_JOB_SEQ

    So when cleaning out the Spring Batch Meta-Data tables (e.g. using truncate or delete from …) ensure the following commands are run afterwards;

    INSERT INTO BATCH_STEP_EXECUTION_SEQ values(0);
    INSERT INTO BATCH_JOB_EXECUTION_SEQ values(0);
    INSERT INTO BATCH_JOB_SEQ values(0);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a Spring-bean: <bean id=myBean class=package.MyBean> <property name=name1 ref=otherBean /> <property name=name2
Let's suggest that I have a bean defined in Spring: <bean id=neatBean class=com... abstract=true>...</bean>
I have a spring TextEncryptor defined like this <bean id=textEncryptor class=org.springframework.security.crypto.encrypt.Encryptors factory-method=text> <constructor-arg value=${security.encryptPassword}
I have a spring controller defined like this: @Controller @RequestMapping(/user) class UserController { ...
I have defined a javax.servlet.Filter and I have Java class with Spring annotations. import
I have a <form:options> in my jsp for which I have defined the path
I have a custom scope defined for my Spring configuration, I want to initialize
I'm using Spring Batch 2.1.5. I have many jobs that are very similar between
I am working with the spring batch data loader . I have 15000 files
I have a bean defined in my spring web application and I am expecting

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.