Implicit JOIN paths
Applies to ✅ Open Source Edition ✅ Express Edition ✅ Professional Edition ✅ Enterprise Edition
Implicit JOINs are one of jOOQ's most powerful synthetic SQL features, which depends entirely on code generation. The code generator produces links between tables that follow "to-one" relationships (i.e. from child table to parent table). This way, it is possible to greatly simplify your queries:
// Get all books, their authors, and their respective language create.select( BOOK.author().FIRST_NAME, BOOK.author().LAST_NAME, BOOK.TITLE, BOOK.language().CD.as("language")) .from(BOOK) .fetch();
The feature has a few feature toggles in the code generator, including:
<configuration> <generator> <generate> <!-- Allowing to turn off the feature entirely. The default is true. --> <implicitJoinPathsToOne>true</implicitJoinPathsToOne> <!-- Influencing how the DefaultGeneratorStrategy generates identifiers. The default is true. When a child table has only one FK towards a parent table, then that path is "unambiguous." In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name. --> <implicitJoinPathsUseTableNameForUnambiguousFKs>true</implicitJoinPathsUseTableNameForUnambiguousFKs> <!-- Tell the KotlinGenerator to generate properties in addition to methods for these paths. Default is true. --> <implicitJoinPathsAsKotlinProperties>true</implicitJoinPathsAsKotlinProperties> </generate> </generator> </configuration>
See the configuration XSD, standalone code generation, and maven code generation for more details.
new org.jooq.meta.jaxb.Configuration() .withGenerator( new Generate() // Allowing to turn off the feature entirely. The default is true. .withImplicitJoinPathsToOne(true) // Influencing how the DefaultGeneratorStrategy generates identifiers. The default is true. // // When a child table has only one FK towards a parent table, then that path is "unambiguous." // In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name. .withImplicitJoinPathsUseTableNameForUnambiguousFKs(true) // Tell the KotlinGenerator to generate properties in addition to methods for these paths. Default is true. .withImplicitJoinPathsAsKotlinProperties(true) )
See the configuration XSD andprogrammatic code generation for more details.
myConfigurationName(sourceSets.main) { generator { generate { // Allowing to turn off the feature entirely. The default is true. implicitJoinPathsToOne = true // Influencing how the DefaultGeneratorStrategy generates identifiers. The default is true. // // When a child table has only one FK towards a parent table, then that path is "unambiguous." // In that case, the DefaultGeneratorStrategy uses the parent table name instead of the FK name. implicitJoinPathsUseTableNameForUnambiguousFKs = true // Tell the KotlinGenerator to generate properties in addition to methods for these paths. Default is true. implicitJoinPathsAsKotlinProperties = true } } }
See the configuration XSD andgradle code generation for more details.
Feedback
Do you have any feedback about this page? We'd love to hear it!