Projects/[Spring] Code Refactoring Project

[Spring Plus] Troubleshooting - @Transactional

montmer27 2026. 2. 27. 16:22
문제 요약

/todos API 호출 시 jakarta.servlet.ServletException 발생

 

문제 상세

문제의 컨트롤러
에러 메시지

에러 로그 원문

jakarta.servlet.ServletException: Request processing failed: org.springframework.orm.jpa.JpaSystemException: could not execute statement [Connection is read-only. Queries leading to data modification are not allowed] [insert into todos (contents,created_at,modified_at,title,user_id,weather) values (?,?,?,?,?,?)]

 

문제 원인 추정

Connection is read-only 라는 점에서 saveTodo가 읽기 전용 메서드로 선언되어 있을 것이고, 그 결과 업데이트 쿼리가 날아갈 수 없었다.

 

문제 원인 확인

모든 메서드에 readOnly = true가 적용되어 있었다.

해결 방법 요약

readOnly = true 옵션 삭제

 

해결 방법 상세

 

readOnly = true 옵션 삭제

결과

정상 실행 확인

인사이트
클래스명에 @Transactional을 붙여서 모든 메서드에 일괄적으로 적용할 수 있다