MyBatis 3 spring - java
我正在尝试批量插入并在有超过1条记录时收到跟踪错误。它与一个recrod完美配合
我相信b / c它在事务中nextval不会在每次迭代时生成nextval。我对此有任何帮助吗?
nested exception is java.sql.SQLIntegrityConstraintViolationException: ORA-00001: unique constraint (LINEAR_UPSELL.SYS_C0016697) violated
我的方法在java文件中有Transaction注释
@Transactional(propagation=Propagation.REQUIRED, readOnly=false, rollbackFor=Exception.class)
mapper文件中的是我的插入语句
<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>
答案 0 :(得分:1)
不能很好地工作。你必须找到如下工作
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>