[Error/Spring/MyBatis] [500] ArrayList cannot be cast to

2023. 8. 16. 23:10Backend/Spring

 

ArrayList cannot be cast to

 

상황
STS3 을 이용하여 Spring project를 진행 중에, repository에서 sqlSession 가 관련하여 만난 에러이다.

 

원인
repository 클래스 내 메서드가 수행한 데이터의 row의 값이 1인데, 다양한 값을 다루는 selectList를 사용하여 발생하였다. 

 

해결

selectList 가 아닌 selectOne으로 변경하여 해결

확인
selectOne() : DB에 하나의 레코드가 있는 경우에 사용
selectList(): DB에 여러 개의 레코드가 있는 경우에 사용