잘 정리해보자

Spring Batch Error : Cannot change the ExecutorType when there is an existing transaction 본문

Spring/Spring Boot

Spring Batch Error : Cannot change the ExecutorType when there is an existing transaction

토마토오이 2022. 1. 10. 21:23

 

에러 메시지 : 

org.springframework.dao.TransientDataAccessResourceException: Cannot change the ExecutorType when there is an existing transaction

 

발생 원인 :

배치 실행 시, AbstractPagingItemReader 로 read구현을 했는데, read함수 안에 paging처리 하면서 다른 dao도 함께 호출해서 발생.

-> paging처리 하는 reader트랜잭션이 동작중인데, 다른 mapper를 호출하면서 트랜잭션 충돌이 발생.

 

 

해결 :

paging처리하는 트랜잭션안에서 동작하려면 session을 열어서 같이 처리시키던가, bean으로 따로 만들어 처리.

 

저는 bean으로 따로 만들어서 처리했습니다.

processor bean으로 만들어 reader 후 processor로 log적재하는 mapper를 호출.

Comments