Unable to make batch insert into Oracle DB using MyBatis

不管现实多么惨不忍睹,都要持之以恒地相信,这只是黎明前短暂的黑暗而已。不要惶恐眼前的难关迈不过去,不要担心此刻的付出没有回报,别再花时间等待天降好运。真诚做人,努力做事!你想要的,岁月都会给你。Unable to make batch insert into Oracle DB using MyBatis,希望对大家有帮助,欢迎收藏,转发!站点地址:www.bmabk.com,来源:原文

I try to make batch insert into table at Oracle database using MyBatis (integrated with Spring) .

It is a definition of method in mapper interface:

public void savePayments(@Param(“payments”) List payments);
It is a MyBatis XML mapper code:

<insert id="savePayments" parameterType="MassPaymentFileItem" useGeneratedKeys="false">
    INSERT INTO mass_payments
        (payment_id, file_id, msisdn, amount, status)
    <foreach collection="payments" item="payment" index="index" separator=" UNION ALL ">
        SELECT SEQ_MASS_PAYMENT.nextval, #{payment.fileId}, #{payment.msisdn}, #{payment.amount}, 0 FROM DUAL
    </foreach>
</insert>

When I execute this I receive MyBatisSystemException with message “nested exception is org.apache.ibatis.builder.BuilderException: Improper inline parameter map format. Should be: #{propName,attr1=val1,attr2=val2}”

What is wrong? How to fix it?

I found that the first answer doesn’t work for me, then i find another solution as below:

<insert id="savePayments" parameterType="java.util.List" useGeneratedKeys="true">
       <selectKey resultType="java.lang.Integer" keyProperty="payment_id"
            order="BEFORE">
            SELECT SEQ_MASS_PAYMENT.nextval as payment_id FROM DUAL
        </selectKey>
        INSERT INTO mass_payments
            (payment_id, file_id, msisdn, amount, status)
            select SEQ_MASS_PAYMENT.nextval, A.* from (
        <foreach collection="payments" item="payment" index="index" separator="UNION ALL">
            SELECT 
            #{payment.fileId} as file_id,
            #{payment.msisdn} as msisdn,
            #{payment.amount} as amount,
            0 as status
            FROM DUAL
        </foreach> ) A
    </insert>

from: https://stackoverflow.com/questions/26278531/unable-to-make-batch-insert-into-oracle-db-using-mybatis/34398186#34398186

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 举报,一经查实,本站将立刻删除。

文章由极客之音整理,本文链接:https://www.bmabk.com/index.php/post/164159.html

(0)
飞熊的头像飞熊bm

相关推荐

发表回复

登录后才能评论
极客之音——专业性很强的中文编程技术网站,欢迎收藏到浏览器,订阅我们!