5

I know right now there is no such thing as inter-step transactionality in Spring-Batch. I'm developing a complex batch job, with many steps performing several actions in database, and each one is related with the others, in such way that each one of them belongs to the same transaction. The way I understand the Spring-Batch paradigm I'm bound to use one-step job in order to have transactionality. Is there any thought (or any other way) to have some kind of job-level transactionality in lately or future versions?

Edit1: I have found in this link, point 6.3.1, a way to concatenate several processors, but that doesn't fulfill my current needs.

Edit2:This other link suggests me the possibility of using an envelope class with "@Transactional" annotation that will invoke my job and, therefore, shall have an external transaction.

mantoviejo
  • 168
  • 1
  • 12
  • did you try to use one step only and placing the logic of "many steps with several actions" in business implementation ? – Michael Pralow Sep 19 '12 at 13:52
  • Yeah, I have tried (and have been bound to in order to go on) use one-step only batches. But I consider, being Spring so adaptable, that would be quite helpful to have a job-level transaction to allow different uses. – mantoviejo Sep 19 '12 at 15:05
  • The foremost error in one-step-only job is you have to add all your business logic inside one (or more) processor(s). This way, I think you are not following the Spring-Batch concept, by adding all the process complexity in one step, and been confined to use DAOs in the processor to achieve your logic goals. – mantoviejo Sep 20 '12 at 06:35
  • 1
    the Problem with transactional Job is: the batch commits 1.000.000 items at once – Michael Pralow Sep 20 '12 at 17:42
  • I assume that depends on the data volume you are managing. Also I consider this potential option as a flexibility improvement in the current Spring Batch. – mantoviejo Sep 21 '12 at 05:53

1 Answers1

3

Finally I have found a way to do this. As said in the last edition you must invoke the job from a transactional method:

@Transactional(propagation=Propagation.REQUIRED)

It's important set the propagation level to required in this level. And set the job level propagation to "mandatory", achieving with this the job and steps add their transactions to the current one. Nevertheless, as Michael Lange wrote, it's important to consider the potential volume size you are managing, in order to avoid out-of-the-limit commits or rollbacks.

mantoviejo
  • 168
  • 1
  • 12