MyBatis 사용 도중 아래와 같은 오류 메시지 발생.
도대체 뭐가 문제일까?
처음엔 아래와 같은 오류로 인해 상당히 혼란 스러웠다.
뭐가 문제지??
org.mybatis.spring.MyBatisSystemException: nested exception is org.apache.ibatis.exceptions.PersistenceException:
### Error querying database. Cause: java.lang.NumberFormatException: For input string: "N"
### Cause: java.lang.NumberFormatException: For input string: "N"
실제 이 오류를 발생한 xml파일 내의 쿼리는 아래와 같다.
다이나믹 쿼리 수행을 위해 추가한 if 절로 인해 발생하는 것이었다. 문법 상의 문제가 없는지 여러번 살폈으나 별다른 이상을 발견하지 못했고, 구글링 도중 발견한 글 중 하나가 바깥에 표기한 큰따옴표(")를 작은따옴표(')로 변경해 보라는 글을 발견했다.
<select id="select_CuttingAndNoCutting" resultMap="CuttingResult" parameterType="java.util.Map">
SELECT cutting_date, nvl(cut, 0) as cut, nvl(nocut, 0) as nocut
FROM ( select cutting_date, sum(order_length) as order_length, cutting_type
from ( SELECT cutting_date, order_length, cutting_type
from cutting_order_circuit
where cutting_date like #{YYYYMM,jdbcType=VARCHAR} || '%'
and drum_no not like '%결품%'
and drum_no is not null
<if test="isPowerCutter == 'Y'">
and (actor = #{actor,jdbcType=VARCHAR}
or actor is null
and powerorder = 'on')
and powercomplete is null
</if>
<if test="isPowerCutter == 'N'">
and actor = #{actor,jdbcType=VARCHAR}
</if>
) group by cutting_date, cutting_type
) PIVOT ( sum(order_length) FOR cutting_type IN ('절단' as cut, '미절단' as nocut))
order by cutting_date
</select>
혹시나 하는 마음에 큰따옴표와 작은따옴표의 위치를 변경한 결과 아무런 문제 없이 내가 예상했던 대로 쿼리가 수행되는 것이었다.
정말 어의없는 상황..이 문제로 상당한 시간을 허비했거늘...
오늘도 이렇게 어의없이 문제를 깔끔하게(?) 해결한 하루 였다.
내가 바꾼 건 따옴표 밖에는 없었다는..
<select id="select_CuttingAndNoCutting" resultMap="CuttingResult" parameterType="java.util.Map">
SELECT cutting_date, nvl(cut, 0) as cut, nvl(nocut, 0) as nocut
FROM ( select cutting_date, sum(order_length) as order_length, cutting_type
from ( SELECT cutting_date, order_length, cutting_type
from cutting_order_circuit
where cutting_date like #{YYYYMM,jdbcType=VARCHAR} || '%'
and drum_no not like '%결품%'
and drum_no is not null
<if test='isPowerCutter == "Y"'>
and (actor = #{actor,jdbcType=VARCHAR}
or actor is null
and powerorder = 'on')
and powercomplete is null
</if>
<if test='isPowerCutter == "N"'>
and actor = #{actor,jdbcType=VARCHAR}
</if>
) group by cutting_date, cutting_type
) PIVOT ( sum(order_length) FOR cutting_type IN ('절단' as cut, '미절단' as nocut))
order by cutting_date