【发布时间】:2018-08-13 02:49:35
【问题描述】:
我有一个看起来像这样的课程
public class ABLink {
private Long aId;
private Long bId;
}
这个类在数据库(Postgresql)中有一个对应的实体,看起来像:
CREATE TABLE a_b_link(
a_id BIGINT NOT NULL,
b_id BIGINT NOT NULL,
CONSTRAINT a_b_link_pk
PRIMARY KEY (a_id, b_id)
);
我正在尝试以这种方式使用 jooq loader api 执行批量插入:
dsl.loadInto(A_B_LINK).batchAll()
.onDuplicateKeyUpdate()
.loadRecords(records)
.fields(A_B_LINK.fields())
.execute();
因为我正在尝试为这种插入逻辑制作一批:
insertInto(A_B_LINK).set(record).onDuplicateKeyUpdate().set(record).execute()
但我遇到过这样的错误:
Batch entry 0 insert into "schema"."a_b_link" ("a_id", "b_id") values (3273, 8) on conflict ("a_id", "b_id") do update set [ no fields are updated ] was aborted: ERROR: syntax error at or near "["
因为没有要更新的字段。只有这个ID。我尝试在 loader api 中使用 onDuplicateKeyUpdate 进行批处理,但收到错误消息:
Cannot apply batch loading with onDuplicateKeyIgnore flag.
我尝试在没有任何重复键策略的情况下执行批处理,例如:
dsl.loadInto(A_B_LINK).batchAll()
.loadRecords(records)
.fields(A_B_LINK.fields())
.execute();
当然,使用这种方法时,我会不时收到违规异常。
我将非常感谢与此问题相关的任何帮助、建议或提示。
【问题讨论】:
-
您好,您是否也可以执行 SQL 插入语句?
-
@JimJones,我不确定我是否理解正确。你问我是否可以通过 dsl.insert 达到我的目标?
标签: java postgresql jooq