2

In Spring batch you can set the transaction isolation and propagation like this:

<job id="someJob" xmlns="http://www.springframework.org/schema/batch">
   <step id="readWriteDate">
      <tasklet transaction-manager="transactionManager">
         <transaction-attributes isolation="DEFAULT" propagation="REQUIRED" timeout="30"/>
         <chunk reader="dbItemReader" processor="dbItemProcessor" writer="dbItemWriter"
                commit-interval="2" />
      </tasklet>
   </step>
</job>

I cant find the java config equivalent.

Evgeni Dimitrov
  • 21,976
  • 33
  • 120
  • 145

2 Answers2

2

well it is there

@Configuration
public class StepWithTx {

    @Autowired
    private StepBuilderFactory steps;

    @Bean
    public Step step() throws Exception {
        return steps
                .get("CustomTxStep")
                .<String, String>chunk(10)
                .transactionAttribute(transactionAttribute...)
                .reader(reader...)
                .processor(processor...)
                .writer(writer...)
                .build();
    }
}

for default implementations take a look at http://docs.spring.io/spring/docs/4.0.5.RELEASE/javadoc-api/org/springframework/transaction/interceptor/package-summary.html

Michael Pralow
  • 6,560
  • 2
  • 30
  • 46
  • 1
    If I put transaction attribute as shown above, I get compile error - **The method reader(ItemReader) is undefined for the type AbstractTaskletStepBuilder>**. Get no error if put after writer() and before build(). – Sabir Khan Jan 25 '17 at 10:01
2

It's like Michael Pralow say. Just to add a concrete example you can set the isolation level by instantiating a default transaction attribute :

  
DefaultTransactionAttribute transactionWithIsolationReadCommited = new DefaultTransactionAttribute();
transactionWithIsolationReadCommited.setIsolationLevel(TransactionAttribute.ISOLATION_READ_COMMITTED);

And then use it in the step builder. Hope it helps!

Mickael B.
  • 233
  • 2
  • 6