From 516e87556c680dcdc7ada7d2a55545f596d527c8 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 3 Nov 2021 17:35:51 +0100 Subject: [PATCH] [jOOQ/jOOQ#9864] Fix Derby ON DUPLICATE KEY / ON CONFLICT --- jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java index 12603d0577..fff2dd5f38 100644 --- a/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/InsertQueryImpl.java @@ -100,6 +100,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; import java.util.Set; +import java.util.stream.Collectors; import org.jooq.Clause; import org.jooq.Condition; @@ -837,7 +838,7 @@ final class InsertQueryImpl extends AbstractStoreQuery impl || !table().getKeys().isEmpty()) { Table t = null; - Collection> k = insertMaps.keysFlattened(ctx); + Set> k = insertMaps.keysFlattened(ctx); Collection> f = null; if (!NO_SUPPORT_SUBQUERY_IN_MERGE_USING.contains(ctx.dialect())) { @@ -879,7 +880,7 @@ final class InsertQueryImpl extends AbstractStoreQuery impl return t != null ? notMatched.whenNotMatchedThenInsert(f).values(t.fields()) - : notMatched.whenNotMatchedThenInsert(k).values(insertMaps.lastMap().values()); + : notMatched.whenNotMatchedThenInsert(k).values(insertMaps.lastMap().entrySet().stream().filter(e -> k.contains(e.getKey())).map(Entry::getValue).collect(toList())); } else throw new IllegalStateException("The ON DUPLICATE KEY IGNORE/UPDATE clause cannot be emulated when inserting into non-updatable tables : " + table());