개발

[에러기록] 쿼리 실행 후 IndexOutOfBoundsException

JK. 2022. 8. 18. 13:17
728x90

2022-08-18 13:06:25.614 ERROR 8396 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException: 
### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 15, Size: 15
### The error may exist in file [C:\intelliJ\cagos\juvee-portal\build\resources\main\mappers\systemApi\SystemApiMapper.xml]
### The error may involve kr.co.idino.iportal.mapper.systemApi.SystemApiMapper.SelectOrdersList
### The error occurred while handling results
### SQL: SELECT no    -    , updated_at    , created_at   FROM orders   WHERE user_no = ?     AND checkout_email = ?
### Cause: java.lang.IndexOutOfBoundsException: Index: 15, Size: 15] with root cause

 

위와 같은 에러가 나타남

눈에 띄는 단어는 IndexOutOfBoundsException

 

IndexOutOfBoundsException는 보통 배열과 가은걸 다룰때 나타나서

지금과 같이 쿼리를 실행할때에는 왜 발생한지를 쉽게 파악을 못했습니다.

 

그래서 에러 메세지 중 java.lang.IndexOutOfBoundsException: Index: 15, Size: 15에서 사이즈가 15라는걸 발견하고

컬럼이 15개라는걸 확인

 

<select id="SelectOrdersList" parameterType="requestOrdersDto" resultType="OrdersDto">

xml에서 resultType부분과 매핑될때 문제가 생긴것 같은 느낌이 들어 확인

OrdersDto파일을 보니 카운트를 세기위해 private it listCnt;라는 코드를 임시로 생성할걸 발견하고 제거해보고 다시 테스트 해봄

 

테스트 결과

java.lang.ClassCastException: java.util.ArrayList cannot be cast to java.util.Map
일단 인덱스를 넘어 참조하던 현상을 사라진것같다.

 

결론 - resultType를 Dto로 설정할경우 Dto에서 설정한 필드만큼은 컬럼을 설정해줘야 할것 같다.