Praveen Kumar
Praveen Kumar

Reputation: 815

Issues with Spring batch Metadata tables

I have been trying to create a Spring batch program which has to read certain data from Database and write it into another table. I don't want the Spring Batch metadata tables to be created in my Database. When I tried that, I was not able to do the transactions.

I avoided the meta data tables by extending DefaultBatchConfigurer and overriding like this,

@Override
    public void setDataSource(DataSource dataSource) {
        // override to do not set datasource even if a datasource exist.
        // initialize will use a Map based JobRepository (instead of database)
    } 

By doing this I was getting org.springframework.dao.InvalidDataAccessApiUsageException: no transaction is in progress; nested exception is javax.persistence.TransactionRequiredException: no transaction is in progress exception.

Is there a way by which I can avoid the metadata tables and still use the transactions?

Upvotes: 2

Views: 2126

Answers (1)

Ankit Mahajan
Ankit Mahajan

Reputation: 96

  1. If your are using spring boot you may add the below line to application.properties or environment specific property file to ensure the spring batch metadata tables are not getting created:

spring.batch.initializer.enabled=false

  1. Also since you do not need the meta tables so do not extend DefaultBatchConfigurer class.

  2. I would only extend this class if I want to set up a persistent JobRepository i.e. create the spring batch meta tables, for which we need a lot of other configurations that are provided by default by DefaultBatchConfigurer class.

Upvotes: 1

Related Questions