From cec7dbb4b57bf57e53f54e01cd6fc1581f2d0871 Mon Sep 17 00:00:00 2001 From: Lukas Eder Date: Wed, 2 Mar 2022 16:14:47 +0100 Subject: [PATCH] [jOOQ/jOOQ#13183] Add Javadoc warnings to UpdatableRecord::fetchChildren, and TableRecord::fetchParent about the N+1 problem --- jOOQ/src/main/java/org/jooq/TableRecord.java | 8 +++++++- .../main/java/org/jooq/UpdatableRecord.java | 18 ++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/jOOQ/src/main/java/org/jooq/TableRecord.java b/jOOQ/src/main/java/org/jooq/TableRecord.java index 0dc6122f8e..766919667e 100644 --- a/jOOQ/src/main/java/org/jooq/TableRecord.java +++ b/jOOQ/src/main/java/org/jooq/TableRecord.java @@ -109,7 +109,13 @@ public interface TableRecord> extends QualifiedRecord * This returns a parent record referenced by this record through a given * foreign key, as if fetching from {@link #parent(ForeignKey)}. If no - * parent record was found, this returns null + * parent record was found, this returns null. + *

+ * A separate roundtrip is created by this operation. It is + * often much better to include parent records using ordinary + * JOIN mechanisms in a single query, or using nested records, + * see https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/nested-records/. * * @throws DataAccessException if something went wrong executing the query * @see ForeignKey#fetchParent(Record) diff --git a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java index 0a09529291..0cbdf021b1 100644 --- a/jOOQ/src/main/java/org/jooq/UpdatableRecord.java +++ b/jOOQ/src/main/java/org/jooq/UpdatableRecord.java @@ -596,6 +596,15 @@ public interface UpdatableRecord> extends TableReco * This returns a child record referencing this record through a given * foreign key, as if fetching from {@link #children(ForeignKey)}.. If no * child record was found, this returns null. + *

+ * A separate roundtrip is created by this operation. It is + * often much better to include parent records using ordinary + * JOIN mechanisms in a single query, or using nested records, + * or the MULTISET or MULTISET_AGG operators, see + * https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/nested-records/, + * or the https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/multiset-value-constructor/. * * @throws DataAccessException if something went wrong executing the query * @throws TooManyRowsException if the query returned more than one record @@ -613,6 +622,15 @@ public interface UpdatableRecord> extends TableReco *

* This returns child records referencing this record through a given * foreign key, as if fetching from {@link #children(ForeignKey)}. + *

+ * A separate roundtrip is created by this operation. It is + * often much better to include parent records using ordinary + * JOIN mechanisms in a single query, or using nested records, + * or the MULTISET or MULTISET_AGG operators, see + * https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/nested-records/, + * or the https://www.jooq.org/doc/latest/manual/sql-building/column-expressions/multiset-value-constructor/. * * @throws DataAccessException if something went wrong executing the query * @see ForeignKey#fetchChildren(java.util.Collection)