IT/프로그래밍

NestedSQLException 오류 중 하나

Collin 2019. 7. 22. 12:15
반응형

새로운 업무를 추가 개발하면서

 

기존 조회 SQL에 조건에 따라서 추가 조회하는 testA 라는 가상 컬럼을 추가했다.

그리고 조회에 사용하는 java 객체에도 해당 testA 변수를 선언해주었다.

 

로컬에서는 별다른 이상없이 서비스되어서 개발 테스트 후 배포를 하였는데

다음과 같은 오류가 뜨기 시작했다.

 

###### ERROR LOG ######
CLASS_NAME : MappedStatement.java / LINE : 208 / MESSAGE : com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in sqlmap/sql/test.xml.  
--- The error occurred while applying a result map.  
--- Check the test.selectTest-AutoResultMap.  
--- Check the result mapping for the 'testA' property.  
--- Cause: java.sql.SQLException: Column 'testA' not found.
CLASS_NAME : MappedStatement.java / LINE : 144 / MESSAGE : com.ibatis.common.jdbc.exception.NestedSQLException:   
--- The error occurred in sqlmap/sql/test.xml.  
--- The error occurred while applying a result map.  
--- Check the test.selectTest-AutoResultMap.  
--- Check the result mapping for the 'testA' property.  
--- Cause: java.sql.SQLException: Column 'testA' not found.
###### END ERROR LOG ###### 

 

위메세지는 조회한 결과를 객체에 매핑하면서 객체에는 있는데, 조회 결과에 없어서 발생한 것인데

추가적으로 항상 있거나 없는게 아니라

있다 없으니까 또는 없다 있으니까 변동적이다 보니

문제가 발생한것으로 보인다.

 

기존 : 특정 상황에 따라 testA 컬럼 있음 or 없음

이후 : 항상 testA 컬럼 있음 ( 특정상황에 따라 값 또는 빈값 )

 

-- 수정 전
select 
<isEqual property="a" compareValue="Y">
case when 1 = 1 then 'Y' else 'N' end as 'testA'
,case when 1 = 2 then 'Y' else 'N' end as 'testB'
</isEqual>
<isEqual property="a" compareValue="N">
case when 1 = 1 then 'Y' else 'N' end as 'testA'
</isEqual>
;

-- 수정 후
select 
<isEqual property="a" compareValue="Y">
case when 1 = 1 then 'Y' else 'N' end as 'testA'
,case when 1 = 2 then 'Y' else 'N' end as 'testB'
</isEqual>
<isEqual property="a" compareValue="N">
case when 1 = 1 then 'Y' else 'N' end as 'testA'
, 'N' as 'testB' /*추가*/
</isEqual>
;

 

이상 2시간 삽질의 결과였습니다.

 

반응형