mybatis insert all nextval unique constraint in @transaction mdoe报错
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>
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>