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 fba44fb6d5..4547999830 100644 --- a/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java +++ b/jOOQ-codegen/src/main/java/org/jooq/codegen/JavaGenerator.java @@ -4884,10 +4884,19 @@ public class JavaGenerator extends AbstractGenerator { out.tab(1).println("public static final %s %s = new %s();", className, schemaId, className); if (generateGlobalTableReferences()) { + Set fieldNames = new HashSet<>(); + fieldNames.add(schemaId); + for (TableDefinition table : schema.getTables()) { + fieldNames.add(getStrategy().getJavaIdentifier(table)); + } + for (TableDefinition table : schema.getTables()) { final String tableClassName = out.ref(getStrategy().getFullJavaClassName(table)); final String tableId = getStrategy().getJavaIdentifier(table); final String tableFullId = getStrategy().getFullJavaIdentifier(table); + String tableShortId = out.ref(getStrategy().getFullJavaIdentifier(table), 2); + if (fieldNames.contains(tableShortId.substring(0, tableShortId.indexOf('.')))) + tableShortId = tableFullId; final String tableComment = !StringUtils.isBlank(table.getComment()) && generateCommentsOnTables() ? escapeEntities(table.getComment()) : "The table " + table.getQualifiedOutputName() + "."; @@ -4895,9 +4904,9 @@ public class JavaGenerator extends AbstractGenerator { out.tab(1).javadoc(tableComment); if (scala) - out.tab(1).println("val %s = %s", tableId, tableFullId); + out.tab(1).println("val %s = %s", tableId, tableShortId); else - out.tab(1).println("public final %s %s = %s;", tableClassName, tableId, tableFullId); + out.tab(1).println("public final %s %s = %s;", tableClassName, tableId, tableShortId); // [#3797] Table-valued functions generate two different literals in // globalObjectReferences diff --git a/jOOQ-examples/jOOQ-flyway-ddl-example/src/main/java/org/jooq/example/flyway/ddl/db/h2/FlywayTest.java b/jOOQ-examples/jOOQ-flyway-ddl-example/src/main/java/org/jooq/example/flyway/ddl/db/h2/FlywayTest.java index 1249cf12bb..fc35c4230e 100644 --- a/jOOQ-examples/jOOQ-flyway-ddl-example/src/main/java/org/jooq/example/flyway/ddl/db/h2/FlywayTest.java +++ b/jOOQ-examples/jOOQ-flyway-ddl-example/src/main/java/org/jooq/example/flyway/ddl/db/h2/FlywayTest.java @@ -30,7 +30,7 @@ import org.jooq.impl.SchemaImpl; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class FlywayTest extends SchemaImpl { - private static final long serialVersionUID = -219514663; + private static final long serialVersionUID = 1570021131; /** * The reference instance of FLYWAY_TEST @@ -40,12 +40,12 @@ public class FlywayTest extends SchemaImpl { /** * The table FLYWAY_TEST.AUTHOR. */ - public final Author AUTHOR = org.jooq.example.flyway.ddl.db.h2.tables.Author.AUTHOR; + public final Author AUTHOR = Author.AUTHOR; /** * The table FLYWAY_TEST.BOOK. */ - public final Book BOOK = org.jooq.example.flyway.ddl.db.h2.tables.Book.BOOK; + public final Book BOOK = Book.BOOK; /** * No further instances allowed diff --git a/jOOQ-examples/jOOQ-jpa-example/src/main/java/org/jooq/example/jpa/jooq/DefaultSchema.java b/jOOQ-examples/jOOQ-jpa-example/src/main/java/org/jooq/example/jpa/jooq/DefaultSchema.java index 2d07fa2f98..2dd88111f9 100644 --- a/jOOQ-examples/jOOQ-jpa-example/src/main/java/org/jooq/example/jpa/jooq/DefaultSchema.java +++ b/jOOQ-examples/jOOQ-jpa-example/src/main/java/org/jooq/example/jpa/jooq/DefaultSchema.java @@ -22,7 +22,7 @@ import org.jooq.impl.SchemaImpl; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class DefaultSchema extends SchemaImpl { - private static final long serialVersionUID = 1552766182; + private static final long serialVersionUID = 1869451816; /** * The reference instance of @@ -32,22 +32,22 @@ public class DefaultSchema extends SchemaImpl { /** * The table ACTOR. */ - public final Actor ACTOR = org.jooq.example.jpa.jooq.tables.Actor.ACTOR; + public final Actor ACTOR = Actor.ACTOR; /** * The table FILM. */ - public final Film FILM = org.jooq.example.jpa.jooq.tables.Film.FILM; + public final Film FILM = Film.FILM; /** * The table FILM_ACTOR. */ - public final FilmActor FILM_ACTOR = org.jooq.example.jpa.jooq.tables.FilmActor.FILM_ACTOR; + public final FilmActor FILM_ACTOR = FilmActor.FILM_ACTOR; /** * The table LANGUAGE. */ - public final Language LANGUAGE = org.jooq.example.jpa.jooq.tables.Language.LANGUAGE; + public final Language LANGUAGE = Language.LANGUAGE; /** * No further instances allowed diff --git a/jOOQ-examples/jOOQ-kotlin-example/src/main/java/org/jooq/example/db/h2/Public.java b/jOOQ-examples/jOOQ-kotlin-example/src/main/java/org/jooq/example/db/h2/Public.java index 20a4590967..2c9820dfcf 100644 --- a/jOOQ-examples/jOOQ-kotlin-example/src/main/java/org/jooq/example/db/h2/Public.java +++ b/jOOQ-examples/jOOQ-kotlin-example/src/main/java/org/jooq/example/db/h2/Public.java @@ -22,7 +22,7 @@ import org.jooq.impl.SchemaImpl; @SuppressWarnings({ "all", "unchecked", "rawtypes" }) public class Public extends SchemaImpl { - private static final long serialVersionUID = -767902874; + private static final long serialVersionUID = -1306251418; /** * The reference instance of PUBLIC @@ -32,22 +32,22 @@ public class Public extends SchemaImpl { /** * The table PUBLIC.AUTHOR. */ - public final Author AUTHOR = org.jooq.example.db.h2.tables.Author.AUTHOR; + public final Author AUTHOR = Author.AUTHOR; /** * The table PUBLIC.BOOK. */ - public final Book BOOK = org.jooq.example.db.h2.tables.Book.BOOK; + public final Book BOOK = Book.BOOK; /** * The table PUBLIC.BOOK_STORE. */ - public final BookStore BOOK_STORE = org.jooq.example.db.h2.tables.BookStore.BOOK_STORE; + public final BookStore BOOK_STORE = BookStore.BOOK_STORE; /** * The table PUBLIC.BOOK_TO_BOOK_STORE. */ - public final BookToBookStore BOOK_TO_BOOK_STORE = org.jooq.example.db.h2.tables.BookToBookStore.BOOK_TO_BOOK_STORE; + public final BookToBookStore BOOK_TO_BOOK_STORE = BookToBookStore.BOOK_TO_BOOK_STORE; /** * No further instances allowed