9

I am using Spring Batch using 2 (maybe more, assume 2 for simplicity) databases. One for storing all the job datas(all the BATCH_* tables). The other for actually running my business logic data. There are some things I dont quite understand.

  1. When I declared my JobRepository I have already specified my TransactionManager, why do I have to do it again on my tasklet?(I am not using the default name on purpose)
  2. I am currently giving tasklet the same TrasactionManager as my JobRepository which is manages different connections from what I am doing inside my steps. Does that mean I have do my own transaction management inside my writer or reader?
  3. If #2 is true, the "What If" in How does Spring Batch transaction management work? will be a problem for me (without doing XA) right? Because my data and job data are in different connections, right?
Community
  • 1
  • 1
lunaspeed
  • 165
  • 1
  • 11

1 Answers1

5

You can use a separate Transaction manager for tasks and the job repository. See here: http://forum.spring.io/forum/spring-projects/batch/39609-using-2-different-datasources-with-spring-batch

Thus, the need to designate two of them.

That being said, even though you can use two separate transaction managers, it doesn't mean that you should. If you don't go XA, then imagine what would happen if a business process ran successfully, but the job data wasn't saved. The next time the batch process ran, Spring Batch would think the job failed, and try to run it again.

Brad
  • 2,261
  • 3
  • 22
  • 32
  • That's what I am worried about. So when not using XA, its best to put batch and data tables in same database right? or make sure every step can be rerun safely? Another thing is the transactionmanager on tasklet for the jdbc call inside my step logic or saving job status? or both? – lunaspeed Sep 16 '15 at 02:05
  • Correct, the manual recommends that you put the batch tables in the same place as your business data, though I suppose you could make steps safely repeatable as well. The transaction manager you can specify either at the tasklet level, the job level, or both, depending on how you want to set it up. They don't have to be the same. – Brad Sep 16 '15 at 03:42