From 8b4abf881a8cc88601386caae3900e44ea850e41 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 8 Apr 2020 11:03:02 +0200 Subject: [PATCH] [jOOQ/jOOQ#10052] Fix ordering of DELETE WHERE emulation MATCHED clauses --- jOOQ/src/main/java/org/jooq/impl/MergeImpl.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java index 734fa96f72..31ad1c3d66 100644 --- a/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java +++ b/jOOQ/src/main/java/org/jooq/impl/MergeImpl.java @@ -1207,8 +1207,11 @@ implements @Override public final MergeImpl deleteWhere(Condition condition) { + // The ordering is to run deletions *before* updates in order to prevent + // constraint violations that may occur from updates, otherwise. + // See https://github.com/jOOQ/jOOQ/issues/7291#issuecomment-610833303 if (matchedClause) - matched.add(new MatchedClause(condition, true)); + matched.add(matched.size() - 1, new MatchedClause(condition, true)); else throw new IllegalStateException("Cannot call where() on the current state of the MERGE statement");