ISSUE 오답 노트

mybatis 에러 해결: java.lang.IndexOutOfBoundsException

ddowulli 2023. 10. 30. 05:38

아래와 같이 에러가 발생했다.

### Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

 

더보기

### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9
### The error may exist in file [D:\eclipse-workspace\fashion-commerce-server\target\classes\mapper\productMapper.xml]
### The error may involve cohttp://m.ccommit.fashionserver.mapper.ProductMapper.getProductList
### The error occurred while handling results
### SQL: SELECT  id,                 name,                 sale_quantity,                 price,                 category_id,                 like_count,                 sale_id,                 create_date,                 update_date         FROM products         WHERE 1 = 1                       AND category_id = ?                                                               ORDER BY like_count DESC
### Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9] with root cause

java.lang.IndexOutOfBoundsException: Index: 9, Size: 9

 

 "message""nested exception is org.apache.ibatis.exceptions.PersistenceException: \r\n### Error querying database.  Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9\r\n### The error may exist in file [D:\\eclipse-workspace\\fashion-commerce-server\\target\\classes\\mapper\\productMapper.xml]\r\n### The error may involve com.ccommit.fashionserver.mapper.ProductMapper.getProductList\r\n### The error occurred while handling results\r\n### SQL: SELECT  id,                 name,                 sale_quantity,                 price,                 category_id,                 like_count,                 sale_id,                 create_date,                 update_date         FROM products         WHERE 1 = 1                       AND category_id = ?                                                               ORDER BY like_count DESC\r\n### Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9"

 

검색창에 Cause: java.lang.IndexOutOfBoundsException: Index: 9, Size: 9 라고 입력하여 해결 방법을 찾아보았다.

다양한 방법들이 있었는데 해결이 되지 않았다. 그러다 DTO에 @Builder 어노테이션을 추가한게 생각이 났고 재검색하여 찾아본 결과 빌터 어노테이션 때문이 맞았다.


에러 수정 전 DTO

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
@Builder

에러 수정 후 DTO

import lombok.Builder;
import lombok.Getter;
import lombok.Setter;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

@Getter
@Setter
@Builder
@NoArgsConstructor
@AllArgsConstructor

 

자세한 설명은 다음에 추가. 

 

 


[출처 및 참고]

https://velog.io/@maketheworldwise/Builder-AllNoArgsConstructor-%EC%A0%9C%EB%8C%80%EB%A1%9C-%EC%95%8C%EA%B3%A0-%EC%82%AC%EC%9A%A9%ED%95%98%EC%9E%90

 

@Builder, @All/NoArgsConstructor 제대로 알고 사용하자!

USE BUILDER ANNOTATION PROPERLY

velog.io