관리 메뉴

IT.FARMER

Spring Transaction is already completed - do not call commit or rollback more than once per transaction 본문

Spring

Spring Transaction is already completed - do not call commit or rollback more than once per transaction

아이티.파머 2016. 3. 7. 09:54
반응형
Transaction is already completed - do not call commit or rollback more than once per transaction


이미 커밋이나 롤백을 실행했으니 더이상 커밋과 롤백을 하지 말라는 오류.

같은 메서드 공간안에서 두번이나 수동으로 커밋과 롤백을 불러들였더니 이런 에러가 발생했다.


for (..... ) {

 .....


try {

transaction.commit();

} carch (Exception e) {

transaction.rollback();

}


}


이렇게 하면 위와 같이 롤백후에도 커밋을 실행하기 때문에 이미 트렌잭션이 이루어 졌다고 오류를 낸다. (같은 메서드안에)

이에 로직을 분리하여   method_1( ) => method_2( ) 로 호출하는 방식으로 변경하면

원하는 트랜젝션 롤백을 수행 할 수 있다.

반응형