Skip to content

Disabling metadata tables in Spring Batch 5 #4383

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
alexanderpkelly opened this issue May 23, 2023 · 4 comments
Closed

Disabling metadata tables in Spring Batch 5 #4383

alexanderpkelly opened this issue May 23, 2023 · 4 comments
Labels
status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details

Comments

@alexanderpkelly
Copy link

alexanderpkelly commented May 23, 2023

In previous versions of Spring Batch my team disabled metadata database creation by specifying an empty DataSource (via a no-op override of DefaultBatchConfigurer's setDataSource method). This forced the job to use a Map-based JobRepository and prevented Spring Batch from trying to create metadata tables on the Db2 database my job interacts with for it's business purposes.

This approach was deprecated and has been completely removed in Spring Batch 5. This is a conundrum for us, because Spring Batch cannot actually create these metadata tables on our Db2 data source (nor do we want it to). I can't seem to find a way to disable this functionality, which seems like it really ought to have a straightforward means of opting out of ( spring.batch.jdbc.initialize-schema=never is seemingly not respected when a "compatible" data source is available to Spring).

Is there something fundamentally wrong with my approach? Why is the metadata model creation now being forced on Spring Batch users? Should it be?

I appreciate any insight/recommendations you have. Thank you!

@alexanderpkelly alexanderpkelly added the status: waiting-for-triage Issues that we did not analyse yet label May 23, 2023
@alexanderpkelly
Copy link
Author

alexanderpkelly commented May 23, 2023

I was able to bypass this issue by overriding DefaultBatchConfiguration's getDataSource method to return an H2 embedded database, but bringing in an embedded database for metadata purposes only seems a little suspect (compared to simply disabling the metadata functionality).

E.g.

public class BatchConfiguration extends DefaultBatchConfiguration {
    @Override
    protected DataSource getDataSource() {
        return new EmbeddedDatabaseBuilder()
            .addScript("classpath:org/springframework/batch/core/schema-drop-h2.sql")
            .addScript("classpath:org/springframework/batch/core/schema-h2.sql")
            .setType(EmbeddedDatabaseType.H2)
            .build();
    }

@fmbenhassine
Copy link
Contributor

Thank you for opening this issue.

It was never possible to "disable" meta-data. A Spring Batch job requires a JobRepository to report its meta-data to. In v5, you can use the JDBC-based job repository with an in-memory database like h2, hsqldb, etc as you did. That is the way to replace the Map-based job repository if you don't want to create tables in the main database. This is mentioned in the migration guide here.

but bringing in an embedded database for metadata purposes only seems a little suspect (compared to simply disabling the metadata functionality).

In that case, you can implement JobRepository as you wish and use it with your jobs and steps. Spring Batch is designed to work against the JobRepository interface, so any repository implementation can be used as long as it adheres to the specified contract.

I am closing this issue for now, but feel free to add a comment here if you need more support on this.

@fmbenhassine fmbenhassine closed this as not planned Won't fix, can't repro, duplicate, stale Jun 14, 2023
@fmbenhassine fmbenhassine added status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details and removed status: waiting-for-triage Issues that we did not analyse yet labels Jun 14, 2023
@fmbenhassine
Copy link
Contributor

@alexanderpkelly I just wanted to mention that we introduced a resourceless job repository implementation in 5.2.0-M2: #4679. Any feedback is welcome to improve things for the RC and then the GA in November.

@Sdksd167
Copy link

@fmbenhassine i removed @enablebatchprocessing and i configured @bean for resourcelessrepository for avoiding meta data table..but i am getting the same error
org.springframework.jdbc.BadSqlGrammarException: PreparedStatementCallback; bad SQL grammar [SELECT JOB_INSTANCE_ID, JOB_NAME
FROM BATCH_JOB_INSTANCE I1
WHERE I1.JOB_NAME = ? AND I1.JOB_INSTANCE_ID = (SELECT MAX(I2.JOB_INSTANCE_ID) FROM BATCH_JOB_INSTANCE I2 WHERE I2.JOB_NAME = ?)

@configuration
public class Jobconfig extends DefaultBtachConfiguration
{
@bean
public JobRepository jobRepository() throws BatchConfigurationException {
ResourcelessJobRepository factory = new ResourcelessJobRepository();
return factory;
}

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: declined Features that we don't intend to implement or Bug reports that are invalid or missing enough details
Projects
None yet
Development

No branches or pull requests

3 participants