New versions: 3.13 | 3.12 | 3.11 | 3.10 | 3.9

Synthetic primary keys

Applies to ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

jOOQ's code generator recognises primary keys that are declared and reported as such by the database. But some databases don't report all keys, or some tables don't have them enabled, or sometimes, a view is a 1:1 representation of an underlying table, but it doesn't expose the key information. In these cases, this regular expression can match all columns that users wish to "pretend" are part of such a primary key. If a composite synthetic primary key is desired, the regular expression should match all columns of that table that are part of the primary key. For example, a composite synthetic primary key consists of (COLUMN1, COLUMN2) in table SCHEMA.TABLE:

XML (standalone and maven)
Programmatic
Gradle
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.10.0.xsd">
  <generator>
    <database>
      <syntheticPrimaryKeys>SCHEMA\.TABLE\.COLUMN(1|2)</syntheticPrimaryKeys>
    </database>
  </generator>
</configuration>
new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()
      .withSyntheticPrimaryKeys("SCHEMA\\.TABLE\\.COLUMN(1|2)")
    )
  )
myConfigurationName(sourceSets.main) {
  generator {
    database {
      syntheticPrimaryKeys = 'SCHEMA\\.TABLE\\.COLUMN(1|2)'
    }
  }
}

As always, when regular expressions are used, they are regular expressions with default flags.

If the regular expression matches column in a table that already has an existing primary key, that existing primary key will be replaced by the synthetic one. It will still be reported as a unique key, though.

Feedback

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

The jOOQ Logo