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 | 3.10

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.

Generated records

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

Every table and view in your database will generate a org.jooq.TableRecord (or org.jooq.UpdatableRecord if there's a primary key) implementation that looks like this:

// JPA annotations can be generated, optionally
@Entity
@Table(name = "BOOK", schema = "TEST")
public class BookRecord extends UpdatableRecordImpl<BookRecord>

// An interface common to records and pojos can be generated, optionally
implements IBook {

    // Every column generates a setter and a getter
    @Override
    public void setId(Integer value) {
        setValue(BOOK.ID, value);
    }

    @Id
    @Column(name = "ID", unique = true, nullable = false, precision = 7)
    @Override
    public Integer getId() {
        return getValue(BOOK.ID);
    }

    // More setters and getters
    public void setAuthorId(Integer value) {...}
    public Integer getAuthorId() {...}

    // Convenience methods for foreign key methods
    public void setAuthorId(AuthorRecord value) {
        if (value == null) {
            setValue(BOOK.AUTHOR_ID, null);
        }
        else {
            setValue(BOOK.AUTHOR_ID, value.getValue(AUTHOR.ID));
        }
    }

    // Navigation methods
    public AuthorRecord fetchAuthor() {
        return create.selectFrom(AUTHOR).where(AUTHOR.ID.eq(getValue(BOOK.AUTHOR_ID))).fetchOne();
    }

    // [...]
}

TableRecord vs UpdatableRecord

If primary key information is available to the code generator, an org.jooq.UpdatableRecord will be generated. If no such information is available, a org.jooq.TableRecord will be generated. Primary key information can be absent because:

  • The table is a view, which does not expose the underlying primary keys
  • The table does not have a primary key
  • The code generator configuration has turned off primary keys usage information usage through one of various flags (see below)
  • The primary key information is not available to the code generator

Flags controlling record generation

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>
    <generate>
      <!-- Allows for turning on records generation: default true -->
      <records>true</records>

      <!-- Optionally, limit records generation to only tables matching this regular expression. -->
      <recordsIncludes>.*</recordsIncludes>

      <!-- Optionally, limit records generation to only tables not matching this regular expression.
           Excludes match before includes. -->
      <recordsExcludes>SYSTEM_TABLE_.*</recordsExcludes>
    </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()

      // Allows for turning on records generation: default true
      .withRecords(true)

      // Optionally, limit records generation to only tables matching this regular expression.
      .withRecordsIncludes(".*")

      // Optionally, limit records generation to only tables not matching this regular expression.
      // Excludes match before includes.
      .withRecordsExcludes("SYSTEM_TABLE_.*")
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    generate {

      // Allows for turning on records generation: default true
      isRecords = true

      // Optionally, limit records generation to only tables matching this regular expression.
      recordsIncludes = ".*"

      // Optionally, limit records generation to only tables not matching this regular expression.
      // Excludes match before includes.
      recordsExcludes = "SYSTEM_TABLE_.*"
    }
  }
}

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

configuration {
  generator {
    generate {

      // Allows for turning on records generation: default true
      records = true

      // Optionally, limit records generation to only tables matching this regular expression.
      recordsIncludes = ".*"

      // Optionally, limit records generation to only tables not matching this regular expression.
      // Excludes match before includes.
      recordsExcludes = "SYSTEM_TABLE_.*"
    }
  }
}

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

generationTool {
  generator {
    generate {

      // Allows for turning on records generation: default true
      records = true

      // Optionally, limit records generation to only tables matching this regular expression.
      recordsIncludes = ".*"

      // Optionally, limit records generation to only tables not matching this regular expression.
      // Excludes match before includes.
      recordsExcludes = "SYSTEM_TABLE_.*"
    }
  }
}

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

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

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>
    <generate>
      <!-- Allows for turning off records generation: default true -->
      <records>true</records>
    </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()

      // Allows for turning off records generation: default true
      .withRecords(true)
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    generate {

      // Allows for turning off records generation: default true
      isRecords = true
    }
  }
}

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

configuration {
  generator {
    generate {

      // Allows for turning off records generation: default true
      records = true
    }
  }
}

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

generationTool {
  generator {
    generate {

      // Allows for turning off records generation: default true
      records = true
    }
  }
}

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

The recordsIncludes and recordsExcludes regular expressions work just like the global includes and excludes regular expressions

Flags influencing generated records

Additional flags from the code generation configuration influence generated records:

  • syntheticPrimaryKeys: This overrides existing primary key information to allow for "custom" primary key column sets, possibly promoting a TableRecord to an UpdatableRecord
  • overridePrimaryKeys: This overrides existing primary key information to allow for unique key to primary key promotion, possibly promoting a TableRecord to an UpdatableRecord
  • includePrimaryKeys: This includes or excludes all primary key information in the generator's database meta data
  • dateAsTimestamp: This influences all relevant getters and setters
  • unsignedTypes: This influences all relevant getters and setters
  • relations: This is needed as a prerequisite for navigation methods
  • daos: Records are a pre-requisite for DAOs. If DAOs are generated, records are generated as well
  • interfaces: If interfaces are generated, records will implement them
  • jpaAnnotations: JPA annotations are used on generated records (details here)
  • jpaVersion: Version of JPA specification is to be used to generate version-specific annotations. If it is omitted, the latest version is used by default. (details here)

Feedback

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

The jOOQ Logo