New versions: Dev (3.14) | Latest (3.13) | 3.12 | 3.11 | 3.10 | 3.9

Override primary keys

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

In some legacy contexts, there might not be any primary key, only a bunch of unique keys, defined in a table. jOOQ cannot pick one of those as the "primary key", and the table won't be generated as a org.jooq.UpdatableRecord. Users can, however, use this regular expression to match all UNIQUE key names that should be used as a table's primary key.

XML configuration (standalone and Maven)

<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
  <generator>
    <database>
      <overridePrimaryKeys>MY_UNIQUE_KEY_NAME</overridePrimaryKeys>
    </database>
  </generator>
</configuration>

Programmatic configuration

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator(
    .withDatabase(new Database()
      .withOverridePrimaryKeys("MY_UNIQUE_KEY_NAME"))));

Gradle configuration

myConfigurationName(sourceSets.main) {
  generator {
    database {
      overridePrimaryKeys = 'MY_UNIQUE_KEY_NAME'
    }
  }
}

If several keys match, a warning is emitted and the first one encountered will be used. This flag will also replace synthetic primary keys, if it matches.

Note again that these expressions are regular expressions with default flags

The jOOQ Logo