쇼핑몰 프로젝트 리팩토링 과정 중에 아래와 같은 에러가 떠서 확인해보니
Request processing failed; nested exception is org.springframework.jdbc.UncategorizedSQLException: Error setting null for parameter #1 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: 부적합한 열 유형: 1111
null을 허용하지 않는 타입이 null이 되는 것 때문이라고 하는데 null 값을 허용하려면 매핑되는 값 뒤에 jdbcType = 타입
을 넣어주면 된다고 한다.
이런식으로
<insert id="exam" parameterType="DTO">
insert into test
values(#{id, jdbcType=VARCHAR}, #{password, jdbcType=VARCHAR}, #{name, jdbcType=VARCHAR})
</insert>
그런데 일일히 수정할 필요 없이 MyBatis 설정 파일에서 아래와 같이 한번에 해결 가능하다고 한다.
< 오류 처리하기 위한 설정 코드>
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
아래와 같이
<configuration>
<settings>
<setting name="cacheEnabled" value="false" />
<setting name="jdbcTypeForNull" value="NULL" />
</settings>
<typeAliases>
<typeAlias type="kr.test.exam" alias="exam"/>
</typeAliases>
<mappers>
<mapper resource="test.xml"/>
</mappers>
</configuration>
settings는 가장 위에 추가 해야 오류가 안난다.
출처: https://haerong22.tistory.com/55 [물흐르듯 개발하다 대박나기:티스토리]