Available in versions: Dev (3.22)

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.

Explicit nullability

Supported by ✅ Open Source Edition   ✅ Express Edition   ✅ Professional Edition   ✅ Enterprise Edition

By default, the jOOQ code generator only generates nullability information on the org.jooq.DataType of a column, UDT attribute, routine parameter, etc. if it is declared NOT NULL, e.g. SQLDataType.INTEGER.nullable(false). All other data types are left with implicit nullability (Nullability.DEFAULT), which is how a data type behaves if its nullability was never specified.

If you prefer the generated meta model to state nullability explicitly on all data types, e.g. because you export DDL from it using Meta.ddl() or compare it to other meta data, where Nullability.DEFAULT and Nullability.NULL are not the same thing, you can turn on the following flag (default: false):

XML (standalone and maven)
Programmatic
Gradle (Kotlin)
Gradle (Groovy)
Gradle (third party)
<configuration>
  <generator>
    <generate>
      <explicitNullability>true</explicitNullability>
    </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()
      .withExplicitNullability(true)
  )

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

import org.jooq.meta.jaxb.*


configuration {
  generator {
    generate {
      isExplicitNullability = true
    }
  }
}

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

configuration {
  generator {
    generate {
      explicitNullability = true
    }
  }
}

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

// The jOOQ-codegen-gradle plugin has been introduced in version 3.19.
// Please use the official plugin instead of the third party plugin that was recommended before.

With the flag turned on, nullable columns are generated with an explicit .nullable(true) call:

// Without <explicitNullability/> (the default)
public final TableField<BookRecord, String> TITLE = createField(DSL.name("TITLE"), SQLDataType.VARCHAR(400), this, "");

// With <explicitNullability>true</explicitNullability>
public final TableField<BookRecord, String> TITLE = createField(DSL.name("TITLE"), SQLDataType.VARCHAR(400).nullable(true), this, "");

Columns that reference a NOT NULL domain type do not receive an explicit .nullable(true) call, even if the database reports the column itself as nullable (as e.g. PostgreSQL does), in order not to override the domain's own nullability.

Feedback

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

The jOOQ Logo