Transaction Management in Spring Parties

I am developing a package using spring package, I have two steps, step1, which updated table1 and another updated table2.

I want if the second step2 fails, then all treatment is canceled (rollback). What should I do?

I have an xml config example below:

<b:step id="Step1" parent="Tache">
    <b:tasklet>
        <b:chunk reader="baseReader" processor="baseProcessor"
             chunk-completion-policy="completionPolicy"  />
    </b:tasklet>
</b:step>

<b:step id="Step2" parent="Tache">
    <b:tasklet>
        <b:chunk reader="baseReaderEcriture" 
            writer="ecritureWriter" chunk-completion-policy="completionPolicy"  />
    </b:tasklet>
</b:step>

<b:job id="batch" parent="Batch">
    <b:step id="step1" parent="Step1" next="step2"/>
    <b:step id="step2" parent="Step2" />
</b:job>

Thanks!

+2
source share
2 answers

You cannot roll back already committed data (after each block - based on the completion policy - your data until the spring-batch metadata is executed), so you cannot automatically roll back all the data stored in step 1.
Perhaps you can use this syntax:

<b:job id="batch" parent="Batch">
    <b:step id="step1" parent="Step1" next="step2"/>
    <b:step id="step2" parent="Step2">
      <next on="ROLLBACK_ALL" to="deleteDataSavedByStep1Step" />
      <end on="*" />
    </b:step>
</b:job>

, , 1, , deleteDataSavedByStep1Step.

+2

All Articles