I am getting this exception with SERIALIZED isolation level on JobRepository in Spring Batch:
org.springframework.dao.CannotSerializeTransactionException: Pr
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.
Increasing the database.maximumPoolSize size from 3 to 5 solved the error.
Had the same issue in a Spring Batch application (Spring Boot 2.3.3). The solution was:
Remove @EnableTransactionManagement
from a @Configuration
class where datasources are configured. (@Transactional
should also be removed.)
Add the following to application.yaml
batch: repository: isolationlevelforcreate: ISOLATION_READ_COMMITTED
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_" />
I have got a workaround for this issue.
Follow below step.
BATCH_JOB_INSTANCE
, BATCH_JOB_EXECUTION
and BATCH_JOB_EXECUTION_PARAMS
table. (don't forget to commit)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>