关于mybatis:记一次未指定jdbcType导致的报错

报错现场还原

一个批量入库的sql本人测试的时候失常,在线上报了

### Error updating database.  Cause: java.sql.SQLSyntaxErrorException: ORA-01790: 表达式必须具备与对应表达式雷同的数据类型    

原来的sql是这样写的

    <insert id="batchInsert">
        insert into
        <include refid="TABLE_NAME"/>
        (
            CID,
            TS,
            PHONE,
            NUM_PACKAGE,
            COST_MONTHPRICE,
            COST_PRICE,
            ONLINE_TIME,
            LOG_TIME
        )
        <foreach collection="list" item="item" separator="union all">
            select
                #{item.cid},
                #{item.ts},
                #{item.phone},
                #{item.numPackage},
                #{item.costMonthprice},
                #{item.costPrice},
                #{item.onlineTime},
                sysdate
            from dual
        </foreach>
    </insert>

其中onlineTime字段在现场有空的状况,狐疑未加jdbcType=DATE的状况下mybatis将这个字段置为了”空串。

  <insert id="batchInsert">
        insert into
        <include refid="TABLE_NAME"/>
        (
            CID,
            TS,
            PHONE,
            NUM_PACKAGE,
            COST_MONTHPRICE,
            COST_PRICE,
            ONLINE_TIME,
            LOG_TIME
        )
        <foreach collection="list" item="item" separator="union all">
            select
                #{item.cid,jdbcType=INTEGER},
                #{item.ts,jdbcType=INTEGER},
                #{item.phone,jdbcType=VARCHAR},
                #{item.numPackage,jdbcType=VARCHAR},
                #{item.costMonthprice,jdbcType=VARCHAR},
                #{item.costPrice,jdbcType=VARCHAR},
                #{item.onlineTime,jdbcType=DATE},
                sysdate
            from dual
        </foreach>
    </insert>

我记得这个jdbcType有时还会引发索引生效的问题,所以当前还是都带上这个配置吧。

评论

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

这个站点使用 Akismet 来减少垃圾评论。了解你的评论数据如何被处理