Announcement Announcement Module
No announcement yet.
Table 'batch_job_instance' already exists error when trying to execute Spring Batch Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Table 'batch_job_instance' already exists error when trying to execute Spring Batch

    Hello everyone,
    I created a new Spring batch job using database functionality using MySql and it works fine the very first time it runs. I see that Spring batch creates the metadata tables and is able to pull data from my product table for use with the batch process. If I run the batch job again, I am getting an error that Table 'batch_job_instance' already exists. So Batch is trying to recreate the metadata tables, even though they have already been created by the previous job. I've been looking around, and I haven't figured out how to tell Spring Batch that the metadata tables have already been created so that it just inserts into the tables instead of trying to recreate them again.

    Any help would be greatly appreciated...thanks!

  • #2
    The Solution

    I found the solution:

    In your launch-context.xml file, notice the enabled attribute of the jdbc:intialize-database configuration. If it is set to true (which it is by default if you don't explicitly note the attribute, Spring Batch will run the script EVERY TIME you execute the batch job, resulting in a SQL Exception if you run it the second time and on because the metadata tables were already created when Spring Batch ran the first time. After running the batch job the first time, set the enabled attribute to false and Spring will no longer run the SQL creation scripts.

    	<jdbc:initialize-database data-source="dataSource" enabled="false">
    		<jdbc:script location="${batch.schema.script}" />