[INFO : jdbc.sqlonly - SQL   :  INSERT INTO TEST (
			SUBJECT
			, BODY_TEXT
			, REMARK_TEXT
			, REGIST_USID
			, UPDT_USID
		)
		VALUES(
		 	'55'
			, '566'
			, NULL
			, 'admin' 
			, 'admin'
		) {FAILED after 24 msec}
com.microsoft.sqlserver.jdbc.SQLServerException: 피연산자 유형 충돌: varbinary은(는) text과(와) 호환되지 않습니다.
	at com.microsoft.sqlserver.jdbc.SQLServerException.makeFromDatabaseError(SQLServerException.java:197)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.getNextResult(SQLServerStatement.java:1493)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.doExecutePreparedStatement(SQLServerPreparedStatement.java:390)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement$PrepStmtExecCmd.doExecute(SQLServerPreparedStatement.java:340)
	at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:4575)
	at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:1400)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeCommand(SQLServerStatement.java:179)
	at com.microsoft.sqlserver.jdbc.SQLServerStatement.executeStatement(SQLServerStatement.java:154)
	at com.microsoft.sqlserver.jdbc.SQLServerPreparedStatement.execute(SQLServerPreparedStatement.java:322)
	at net.sf.log4jdbc.PreparedStatementSpy.execute(PreparedStatementSpy.java:418)
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:44)
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:69)
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:48)
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:105)
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:71)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:152)
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:141)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:358)
	at com.sun.proxy.$Proxy16.insert(Unknown Source)
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:240)
	at org.apache.ibatis.binding.MapperMethod.execute(MapperMethod.java:51)
	at org.apache.ibatis.binding.MapperProxy.invoke(MapperProxy.java:52)
	at com.sun.proxy.$Proxy25.insert(Unknown Source)

 

남이 세팅해놓은 spring mybatis 를 사용하다보니 

전에는 못봤던 에러가 계속나니까 당황스러움.

 

DB는 mssql 

문제가 된 컬럼은 text 타입이다.

null값이 insert될때  위와 같은 Exception 발생

물론 컬럼은 nullable이다.

 

원인은 null값이 varvarbinary타입으로 매핑되어서

text타입 컬럼에 집어넣으려니 그런모양

 

	<insert id="insert" parameterType="map">
		INSERT INTO TEST (
			SUBJECT
			, BODY_TEXT
			, REMARK_TEXT
			, REGIST_USID
			, UPDT_USID
		)
		VALUES(
		 	#{subject }
			, #{body_text }
			, #{remark_text, jdbcType=VARCHAR}
			, #{regist_usid } 
			, #{updt_usid }
		)
	</insert>

일단 문제가 된 컬럼 value에 명시적으로 jdbcType=VARCHAR을 선언하면 해당 에러는 더이상 나지 않는다.

 

 

 

 

 

 

 

그럼 그전의 mybatis 사용시에는 왜 이런 에러를 구경 못해봤을까?

 

 

↓ mybatis 설정

	<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
  		<property name="dataSource" ref="dataSource" />
		<property name="mapperLocations">
			<list>
				<value>classpath:/com/**/*.xml</value>
			</list>
		</property>
		<property name="configLocation" value="classpath:/config/mybatis/mybatis-config.xml" />
	</bean>

 

mybatis-config.xml 파일 내용

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE configuration PUBLIC "-//mybatis.org//DTD Config 3.0//EN" "HTTP://mybatis.org/dtd/mybatis-3-config.dtd">
<configuration>
	<settings>
		<setting name="jdbcTypeForNull" 		value="VARCHAR" />
	</settings>
</configuration>

 

기존에는 위와 같이 Null값의 기본 jdbc타입을 설정해놓았기 때문인듯..

 

 

'Java > Servlet' 카테고리의 다른 글

web.xml 에러 페이지 설정  (1) 2018.07.25
Spring MVC Controller에서 ServletContext 사용하기  (0) 2017.09.21
Log4j 설정파일 위치 지정하기  (0) 2014.03.14
JSTL loop  (0) 2014.03.14
Servlet Filter에서 Spring Bean 사용  (1) 2014.03.14
:
Posted by 정규식