今天在框架升级过程中,所有涉及到xml文件中的insert的接口全部报错。错误信息:org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: java.sql.SQLException: Invalid column type ; uncategorized SQLException for SQL []; SQL state [null]; error code [17004]; Invalid column type; nested exception is java.sql.SQLException: Invalid column type
这是在Oracle数据库中插入的属性为null的时候,mybaits会将其转换为JdbcType.OTHER类型。
知道原因后,我选择在配置文件加入:
<settings>
<setting name="jdbcTypeForNull" value="NULL"/>
</settings>
当然我们也可以在可能为null的属性后面加入:
jdbcType=NULL
//例如:
<insert id="insertBatchData" parameterType="java.util.List" useGeneratedKeys="false">
insert into RELALIST_XXXXX_MANUAL(<include refid="Base_Column_List"></include>)
select SEQ_RELALIST_PERSON_MANUAL.nextval,temp.* from(
<foreach collection="list" index="index" item="item" separator=" union all">
select
#{item.personId},#{item.personNm},#{item.relationId},#{item.relationNm},#{item.relationTypeCodeL1}
,#{item.relationTypeL1},#{item.isDel},#{item.createBy,jdbcType=NULL},#{item.updtBy,jdbcType=NULL},#{item.relaPartyType,jdbcType=NULL},#{item.coreColumn,jdbcType=NULL},#{item.srcCd,jdbcType=NULL}
from dual
</foreach>
) temp
</insert>