1、问题描述:
关键信息:Mybatis;Oracle
(1)保存信息到Oracle时报错:
Caused by: org.apache.ibatis.type.TypeException: Error setting null for parameter #10 with JdbcType OTHER . Try setting a different JdbcType for this parameter or a different jdbcTypeForNull configuration property. Cause: java.sql.SQLException: ORA-17004: 列类型无效: 1111
(2)Oracle字段:
TRX_CHANL VARCHAR2(2) DEFAULT '',
varchar 类型 可空
(3)mapper.xml
XML
<resultMap id="baseResultMap" type="com.xxx.infra.po.XXXInfoPO">
<result column="trx_chanl" jdbcType="VARCHAR" property="trxChanl"/>
</resultMap>
<insert id="insert" parameterType="com.xxx.infra.po.XXXInfoPO">
insert into xxx_info (msg,trx_chanl) values (#{msg},#{trxChanl})
</insert>
2、解决
XXXInfoPO 没有给 属性trxChanl赋值时,保存Oracle就会报错 列类型无效: 1111,这时需要给属性trxChanl 指定属性的类型 #{trxChanl,jdbcType=VARCHAR (注意没有"")。这点Oracle跟MySQL是不一样的
XML
<insert id="insert" parameterType="com.xxx.infra.po.XXXInfoPO">
insert into xxx_info (msg,trx_chanl) values (#{msg,jdbcType=VARCHAR},#{trxChanl,jdbcType=VARCHAR})
</insert>