diff --git a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java index deb3c2d4ec..00a602bf62 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -7908,7 +7908,7 @@ public class JavaGenerator extends AbstractGenerator { // Foreign keys List outboundFKs = table.getForeignKeys(); List inboundFKs = table.getInverseForeignKeys(); - Set outboundKeyMethodNames = new HashSet<>(); + Map keyMethodNames = new HashMap<>(); // [#1234] Avoid compilation errors when FK identifiers clash with generated path names if (kotlin && generateGlobalKeyReferences()) { @@ -7973,7 +7973,7 @@ public class JavaGenerator extends AbstractGenerator { // [#13008] Prevent conflicts with the below leading underscore final String unquotedKeyMethodName = keyMethodName.replace("`", ""); - outboundKeyMethodNames.add(keyMethodName); + keyMethodNames.put(keyMethodName, foreignKey); if (scala || kotlin) {} else { @@ -8020,12 +8020,13 @@ public class JavaGenerator extends AbstractGenerator { inboundFKLoop: for (InverseForeignKeyDefinition foreignKey : inboundFKs) { final String keyMethodName = out.ref(getStrategy().getJavaMethodName(foreignKey)); + final Definition previousKey; - if (!outboundKeyMethodNames.add(keyMethodName)) { + if ((previousKey = keyMethodNames.putIfAbsent(keyMethodName, foreignKey)) != null) { log.warn("Ambiguous key name", - "The database object " + foreignKey.getQualifiedOutputName() - + " generates an inbound key method name " + keyMethodName - + " which conflicts with the previously generated outbound key method name." + "The one-to-many key " + foreignKey + + " generates an inbound key method name " + keyMethodName + " on table " + table + + " which conflicts with the previously generated key method name for key " + previousKey + " Use a custom generator strategy to disambiguate the types. More information here:\n" + " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/\n" + " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy/" @@ -8094,12 +8095,13 @@ public class JavaGenerator extends AbstractGenerator { manyToManyKeyLoop: for (ManyToManyKeyDefinition manyToManyKey : manyToManyKeys) { final String keyMethodName = out.ref(getStrategy().getJavaMethodName(manyToManyKey)); + final Definition previousKey; - if (!outboundKeyMethodNames.add(keyMethodName)) { + if ((previousKey = keyMethodNames.putIfAbsent(keyMethodName, manyToManyKey)) != null) { log.warn("Ambiguous key name", - "The database object " + manyToManyKey.getQualifiedOutputName() - + " generates an inbound key method name " + keyMethodName - + " which conflicts with the previously generated outbound key method name." + "The many-to-many key " + manyToManyKey + + " generates an inbound key method name " + keyMethodName + " on table " + table + + " which conflicts with the previously generated key method name for key " + previousKey + "." + " Use a custom generator strategy to disambiguate the types. More information here:\n" + " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-generatorstrategy/\n" + " - https://www.jooq.org/doc/latest/manual/code-generation/codegen-matcherstrategy/" diff --git a/jOOQ-meta/src/main/java/org/jooq/meta/DefaultManyToManyKeyDefinition.java b/jOOQ-meta/src/main/java/org/jooq/meta/DefaultManyToManyKeyDefinition.java index cb72fd3327..3edb184d30 100644 --- a/jOOQ-meta/src/main/java/org/jooq/meta/DefaultManyToManyKeyDefinition.java +++ b/jOOQ-meta/src/main/java/org/jooq/meta/DefaultManyToManyKeyDefinition.java @@ -79,4 +79,9 @@ public class DefaultManyToManyKeyDefinition extends AbstractConstraintDefinition public ForeignKeyDefinition getForeignKey2() { return foreignKey2; } + + @Override + public String toString() { + return "(" + foreignKey1.getQualifiedName() + ", " + foreignKey2.getQualifiedName() + ")"; + } }