CardsFan
CardsFan

Reputation: 75

Spring Batch 4.0 and Spring Boot 1.5.9

Getting up to speed with Spring Batch and Spring Boot wanting to use only annotations. Got the demo application https://spring.io/guides/gs/batch-processing/ working which uses hsqldb and all worked. After that I opted to switch to oracle. I want to use the repository database tables as our older jobs have done. When I switch to oracle 11g the insertrs into the spring batch tables complain about SERILIZABLE. So spending a good part of yesterday chasing this down, I understand that I probably need to do set a isolation level on the jobrepository. Problem is no site goes into this, and the docs showing xml/java do not explain clearly either. I check out the examples from Spring Batch github and cannot find anything there either. Is there an example somewhere of how to create and job repository and change the isolation level for this? Burning hours at this time with no forward motion.

Tried this below code setting the isolation and get: BatchConfigurationException: java.lang.IllegalArgumentException: Invalid transaction attribute token: [READ_COMMITTED]

public class BatchConfiguration extends DefaultBatchConfigurer {
    @Autowired
    public JobBuilderFactory jobBuilderFactory;

    @Autowired
    private PlatformTransactionManager transactionManager;


    @Autowired
    public StepBuilderFactory stepBuilderFactory;

    @Autowired
    private DataSource dataSource;

    @Override
    protected JobRepository createJobRepository() throws Exception {
        JobRepositoryFactoryBean factory = new JobRepositoryFactoryBean();
        factory.setDataSource(dataSource);
        factory.setTransactionManager(transactionManager);
          factory.setIsolationLevelForCreate("READ_COMMITTED");
        //     factory.setTablePrefix("BATCH_");
        factory.setMaxVarCharLength(1000);
        return factory.getObject();
    }

    @Bean
    public JdbcCursorItemReader<BusnPrtnr> itemReader() {
        return new JdbcCursorItemReaderBuilder<BusnPrtnr>()
                .dataSource(dataSource)
...

Upvotes: 1

Views: 1482

Answers (1)

Mahmoud Ben Hassine
Mahmoud Ben Hassine

Reputation: 31590

There is an error in the Java code example here: https://docs.spring.io/spring-batch/4.0.x/reference/html/job.html#txConfigForJobRepository

It should be factory.setIsolationLevelForCreate("ISOLATION_REPEATABLE_READ"); instead of factory.setIsolationLevelForCreate("REPEATABLE_READ");.

The XML code example is correct (the XML parser adds the ISOLATION_ prefix behind the scene).

There is a pull request to fix this issue here: https://github.com/spring-projects/spring-batch/pull/577/files#diff-de2cb44d4395c5ad35d1fc05bbace8f1R620

The fix will be part of 4.0.1 release.

Upvotes: 1

Related Questions