Spring Batch ORA-08177: can't serialize access for this transaction when running single job, SERIALIZED isolation level

前端 未结 9 486
后悔当初
后悔当初 2020-12-01 07:58

I am getting this exception with SERIALIZED isolation level on JobRepository in Spring Batch:

org.springframework.dao.CannotSerializeTransactionException: Pr         


        
相关标签:
9条回答
  • 2020-12-01 08:33

    From official doc - 4.3.1

    The default isolation level for that method is SERIALIZABLE, which is quite aggressive: READ_COMMITTED would work just as well; READ_UNCOMMITTED would be fine if two processes are not likely to collide in this way. However, since a call to the create* method is quite short, it is unlikely that the SERIALIZED will cause problems, as long as the database platform supports it.

    0 讨论(0)
  • 2020-12-01 08:34

    Increasing the database.maximumPoolSize size from 3 to 5 solved the error.

    0 讨论(0)
  • 2020-12-01 08:41

    Had the same issue in a Spring Batch application (Spring Boot 2.3.3). The solution was:

    1. Remove @EnableTransactionManagement from a @Configuration class where datasources are configured. (@Transactional should also be removed.)

    2. Add the following to application.yaml

        batch:
          repository:
            isolationlevelforcreate: ISOLATION_READ_COMMITTED
    
    0 讨论(0)
  • 2020-12-01 08:44

    I had the same problem, and effectively isolation in jobRepository level is the key, here is an example of code that works for me:

    <batch:job-repository id="jobRepository"
        data-source="dataSource" transaction-manager="transactionManager"
        isolation-level-for-create="READ_COMMITTED" table-prefix="SB_" />   
    
    0 讨论(0)
  • 2020-12-01 08:47

    I have got a workaround for this issue.

    Follow below step.

    1. Manually create table in your database (Link).
    2. insert some dummy records in BATCH_JOB_INSTANCE, BATCH_JOB_EXECUTION and BATCH_JOB_EXECUTION_PARAMS table. (don't forget to commit)
    3. Error solved. enjoy.
    0 讨论(0)
  • 2020-12-01 08:48

    I was able to resolve this error by adding isolationLevelForCreate like below:

    <bean id="jobRepository" class="org.springframework.batch.core.repository.support.JobRepositoryFactoryBean">
            <property name="databaseType" value="ORACLE"/>
            <property name="dataSource" ref="dataSource" />
            <property name="transactionManager" ref="transactionManager" />
            <property name="isolationLevelForCreate" value="ISOLATION_READ_UNCOMMITTED"/>
        </bean>
    
    0 讨论(0)
提交回复
热议问题