1

I want to create a spring-batch job, which will save data into SQL Server tables, but I want to run it without any meta data database persistence. Unfortunately spring-batch requires to write metadata information of job execution.

I don't want those BATCH table to be created. How can I do this.

DanzerZoneJS
  • 441
  • 3
  • 7
  • 23
  • Does this answer your question? [Spring-Batch without persisting metadata to database?](https://stackoverflow.com/questions/25077549/spring-batch-without-persisting-metadata-to-database) – Mahmoud Ben Hassine Sep 18 '20 at 15:01

1 Answers1

1

Those tables are required for proper functioning of the spring-batch framework features, so I don't think its a good idea. However Spring does provide a in-memory solution.

The JobRepository has a few Dao classes. Eg. JobInstanceDao, JobExecutionDao etc. All of these by default use the JDBC implementation. But Spring also provides a in-memory implementation for these eg. MapJobInstanceDao for JobInstanceDao. You can easily inject these through the constructor of SimpleJobRepository.

Rahul
  • 289
  • 2
  • 7
  • I have tried MapJobRepositoryFactoryBean but in that case I am using ResourcelessTransactionManager which is causing issue. I am not being able to save data after that. – DanzerZoneJS Sep 18 '20 at 14:40
  • Seems like you are using the same transaction manager globally ? Make sure the `ResourcelessTransactionManager` is not picked up by the business logic classes. – Rahul Sep 18 '20 at 15:27
  • How to have separate transaction manager for JPA repository. I tried using @Transactional at service layer but it did not help. – DanzerZoneJS Sep 18 '20 at 16:06
  • I am sure you already have some transaction manager setup. Keep it as is. Define a bean of `ResourcelessTransactionManager` and pass it into the `MapJobRepositoryFactoryBean` only. Unless I am missing something this should work. – Rahul Sep 18 '20 at 17:51
  • `ResourcelessTransactionManager` is basically a no-op transaction manager. Using this essentially means dropping support of transactions. – Rahul Sep 18 '20 at 17:55
  • I don't have any transaction manager setup for JPA as it is already handled by JPA, but it is not working in case I am using Resourcelesstransactionmanager for MapJobRepositoryFactoryBean. Can you suggest some examples. – DanzerZoneJS Sep 19 '20 at 07:17
  • Do it like following, inject `ResourcelessTransactionManager` into MapJobRepositoryFactoryBean – Rahul Sep 19 '20 at 07:42
  • Tried this but still facing same issue. Batch is running with Map based repository but not saving data into db. – DanzerZoneJS Sep 22 '20 at 08:25