Available in versions: Dev (3.20) | Latest (3.19) | 3.18 | 3.17 | 3.16 | 3.15 | 3.14 | 3.13 | 3.12 | 3.11

This documentation is for the unreleased development version of jOOQ. Click on the above version links to get this documentation for a supported version of jOOQ.

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)
  • to-many relationships (i.e. from parent table to child table)
  • many-to-many relationships (i.e. from parent table 1 to relationship table to parent table 2)

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:

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>
    <generate>

      <!-- Allowing to turn off the feature for to-one join paths.
           The default is true. -->
      <implicitJoinPathsToOne>true</implicitJoinPathsToOne>

      <!-- Allowing to turn off the feature for to-many join paths (including many-to-many).
           The default is true. -->
      <implicitJoinPathsToMany>true</implicitJoinPathsToMany>

      <!-- Whether implicit join path constructors should also be generated if there
           isn't any outgoing or incoming foreign key relationship.
           The default is false. -->
      <implicitJoinPathUnusedConstructors>false</implicitJoinPathUnusedConstructors>
      <!-- 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.
           The 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 for to-one join paths.
      // The default is true.
      .withImplicitJoinPathsToOne(true)

      // Allowing to turn off the feature for to-many join paths (including many-to-many).
      // The default is true.
      .withImplicitJoinPathsToMany(true)

      // Whether implicit join path constructors should also be generated if there
      // isn't any outgoing or incoming foreign key relationship.
      // The default is false.
      .withImplicitJoinPathUnusedConstructors(false)

      // 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.
      // The default is true.
      .withImplicitJoinPathsAsKotlinProperties(true)
  )

See the configuration XSD and programmatic code generation for more details.

import org.jooq.meta.jaxb.*


configuration {
  generator {
    generate {

      // Allowing to turn off the feature for to-one join paths.
      // The default is true.
      isImplicitJoinPathsToOne = true

      // Allowing to turn off the feature for to-many join paths (including many-to-many).
      // The default is true.
      isImplicitJoinPathsToMany = true

      // Whether implicit join path constructors should also be generated if there
      // isn't any outgoing or incoming foreign key relationship.
      // The default is false.
      isImplicitJoinPathUnusedConstructors = false

      // 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.
      isImplicitJoinPathsUseTableNameForUnambiguousFKs = true

      // Tell the KotlinGenerator to generate properties in addition to methods for these paths.
      // The default is true.
      isImplicitJoinPathsAsKotlinProperties = true
    }
  }
}

See the configuration XSD and gradle code generation for more details.

configuration {
  generator {
    generate {

      // Allowing to turn off the feature for to-one join paths.
      // The default is true.
      implicitJoinPathsToOne = true

      // Allowing to turn off the feature for to-many join paths (including many-to-many).
      // The default is true.
      implicitJoinPathsToMany = true

      // Whether implicit join path constructors should also be generated if there
      // isn't any outgoing or incoming foreign key relationship.
      // The default is false.
      implicitJoinPathUnusedConstructors = false

      // 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.
      // The default is true.
      implicitJoinPathsAsKotlinProperties = true
    }
  }
}

See the configuration XSD and gradle code generation for more details.

generationTool {
  generator {
    generate {

      // Allowing to turn off the feature for to-one join paths.
      // The default is true.
      implicitJoinPathsToOne = true

      // Allowing to turn off the feature for to-many join paths (including many-to-many).
      // The default is true.
      implicitJoinPathsToMany = true

      // Whether implicit join path constructors should also be generated if there
      // isn't any outgoing or incoming foreign key relationship.
      // The default is false.
      implicitJoinPathUnusedConstructors = false

      // 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.
      // The default is true.
      implicitJoinPathsAsKotlinProperties = true
    }
  }
}

See the configuration XSD and gradle code generation for more details.

Feedback

Do you have any feedback about this page? We'd love to hear it!

The jOOQ Logo