728x90
반응형
▶ 프로젝트
https://soheepark.tistory.com/183
[에러 메시지]
com.ibatis.common.jdbc.exception.NestedSQLException:
Caused by: java.lang.RuntimeException: Error setting property 'setACount' of 'DTO@5f809fea'.
Caused by: java.lang.IllegalArgumentException
1. 원인
IllegalArgumentException이 발생한 원인은 setACount 메서드에서 잘못된 값을 설정하려고 했기 때문이다.
주로 DB에서 반환된 값을 DTO에 설정하는 과정에서 발생할 수 있다.
SQL 쿼리와 DTO 필드 타입이 문제였다.
ACount는 숫자 타입의 결과값으로 SQL 쿼리에 사용되었고,
int 타입의 DTO 필드였다.
여기서 A들을 그룹화하여 count 액션을 취해준 값이 ACount이다.
[XML]
SELECT ACount
[DTO]
private int ACount;
public void setACount(Int ACount) {
this.ACount = ACount;
}
public int getACount() {
return ACount;
}
위와 같은 기존 코드에서의 문제점은
SQL 쿼리에서 반환되는 값이 NULL이거나 int로 변환할 수 없는 값일 경우 문제가 발생할 수 있다는 것이다.
따라서 아래와 같이 코드를 수정하면 된다.
- DTO : ACount 필드 타입을 Integer로 변경
- XML : NVL(ACount, 0)으로 수정
2. 해결
[XML]
SELECT NVL(ACount, 0)
[DTO]
private Integer ACount;
public void setACount(Integer ACount) {
this.ACount = ACount;
}
public Integer getACount() {
return ACount;
}
위와 같이 코드를 수정해주었더니 에러가 해결되었다.
728x90
반응형
'[Project] > 업무일지' 카테고리의 다른 글
[Java/XML/SQL/Oracle] NestedSQLException, SQLSyntaxErrorException: ORA-00911: invalid character (0) | 2024.07.17 |
---|---|
[Java] NullPointerException (0) | 2024.07.17 |
[Java/Java Swing] ArrayIndexOutOfBoundsException (0) | 2024.07.12 |
[XML/SQL/Oracle] SQLSyntaxErrorException: ORA-00911: invalid character (0) | 2024.07.11 |
[XML/SQL/Oracle] SQLSyntaxErrorException: ORA-02000: missing WITHIN keyword (0) | 2024.07.10 |