From a548c8229853ff214f556bb59a4585ec86b5cd04 Mon Sep 17 00:00:00 2001 From: lukaseder Date: Fri, 7 Oct 2016 11:37:44 +0200 Subject: [PATCH] [#5578] Incorrect ambiguity warning when column name appears in 3+ joined tables --- jOOQ/src/main/java/org/jooq/impl/Fields.java | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/jOOQ/src/main/java/org/jooq/impl/Fields.java b/jOOQ/src/main/java/org/jooq/impl/Fields.java index b338d95867..58763832b4 100644 --- a/jOOQ/src/main/java/org/jooq/impl/Fields.java +++ b/jOOQ/src/main/java/org/jooq/impl/Fields.java @@ -101,29 +101,38 @@ final class Fields extends AbstractQueryPart implements Record // [#4283] table / column matches are better than only column matches Field columnMatch = null; + Field columnMatch2 = null; String tableName = tableName(field); String fieldName = field.getName(); for (Field f : fields) { + String fName = f.getName(); + if (tableName != null) { String tName = tableName(f); - if (tName != null && tableName.equals(tName) && f.getName().equals(fieldName)) + if (tName != null && tableName.equals(tName) && fName.equals(fieldName)) return (Field) f; } // In case no exact match was found, return the first field with matching name - if (f.getName().equals(fieldName)) { + if (fName.equals(fieldName)) { if (columnMatch == null) columnMatch = f; else // [#4476] [#4477] This might be unintentional from a user - // perspective, e.g. when ambiguous ID columns are present. - log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + f + " match.", new SQLWarning()); + // perspective, e.g. when ambiguous ID columns are present. + // [#5578] Finish the loop, though, as we might have an exact match + // despite some ambiguity + columnMatch2 = f; } } + if (columnMatch2 != null) + if (log.isInfoEnabled()) + log.info("Ambiguous match found for " + fieldName + ". Both " + columnMatch + " and " + columnMatch2 + " match.", new SQLWarning()); + return (Field) columnMatch; }