簡體   English   中英

mybatis在@transaction mdoe中插入所有nextval唯一約束錯誤

[英]mybatis insert all nextval unique constraint error in @transaction mdoe

MyBatis 3 Spring-Java

我正在嘗試批量插入,並在有1條以上記錄時收到以下錯誤。 一個推桿就可以完美地工作

我相信b / c是在事務中nextval不會在每次迭代中生成nextval。 我對此有任何幫助嗎?

nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (LINEAR_UPSELL.SYS_C0016697) violated

而且我的方法在java文件中有事務注釋

@Transactional(propagation=Propagation.REQUIRED, readOnly=false, rollbackFor=Exception.class)

在映射器文件中以下是我的插入語句

<insert id="insertService" parameterType="java.util.List">
    insert all
    <foreach collection="list" item="ch" index="index" >
    into tva_upselladmin_channel (id, source_id, service_id, name) values  (
        TVA_UPSELLADMIN_CHANNEL_SEQ.nextVal,
        #{ch.sourceId}, 
        #{ch.serviceId}, 
        #{ch.name}
        )
    </foreach>
            SELECT * FROM dual
</insert>

在oracle中,nextval與insert all語句不能很好地配合。 您必須找到以下解決方法

extractvalue(dbms_xmlgen.getxmltype('select TVA_UPSELLADMIN_CHANNEL_SEQ.nextval - 1 from dual'),'//text()')

如下完整插入不知道-1。

<insert id="insertServiceMappings" parameterType="java.util.List">
    insert all
    <foreach collection="list" item="channel" index="index" >
    into tva_upselladmin_channel (id, source_id, service_id, name) values  (
        extractvalue(dbms_xmlgen.getxmltype('select TVA_UPSELLADMIN_CHANNEL_SEQ.nextval - 1 from dual'),'//text()'),
        #{channel.sourceId}, 
        #{channel.serviceId}, 
        #{channel.name}
        )
    </foreach>
            SELECT * FROM dual
</insert>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM