New versions: Dev (3.15) | Latest (3.14) | 3.13 | 3.12 | 3.11 | 3.10 | 3.9 | 3.8 | Old versions: 3.7 | 3.6 | 3.5 | 3.4 | 3.3

Data type rewrites

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

Sometimes, the actual database data type does not match the SQL data type that you would like to use in Java. This is often the case for ill-supported SQL data types, such as BOOLEAN or UUID. jOOQ's code generator allows you to apply simple data type rewriting. The following configuration will rewrite IS_VALID columns in all tables to be of type BOOLEAN.

XML (standalone and maven)
Programmatic
Gradle
<configuration xmlns="http://www.jooq.org/xsd/jooq-codegen-3.13.0.xsd">
  <generator>
    <database>
    
      <!-- Associate data type rewrites with database columns -->
      <forcedTypes>
        <forcedType>
          <!-- Specify any data type that is supported in your database, or if unsupported, 
               a type from org.jooq.impl.SQLDataType -->
          <name>BOOLEAN</name>
    
          <!-- A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions.
               
               If provided, both "includeExpression" and "includeTypes" must match. -->
          <includeExpression>.*\.IS_VALID</includeExpression>
          
          <!-- A Java regex matching data types to be forced to have this type.
          
               Data types may be reported by your database as:
               - NUMBER              regexp suggestion: NUMBER
               - NUMBER(5)           regexp suggestion: NUMBER\(5\)
               - NUMBER(5, 2)        regexp suggestion: NUMBER\(5,\s*2\)
               - any other form.
               
               It is thus recommended to use defensive regexes for types.
               
               If provided, both "includeExpression" and "includeTypes" must match. -->
          <includeTypes>.*</includeTypes>
        </forcedType>
      </forcedTypes>
    </database>
  </generator>
</configuration>
new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator()
    .withDatabase(new Database()

      // Associate data type rewrites with database columns
      .withForcedTypes(
        new ForcedType()

          // Specify any data type that is supported in your database, or if unsupported, 
          // a type from org.jooq.impl.SQLDataType
          .withName("BOOLEAN")

          // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions.
          // 
          // If provided, both "includeExpression" and "includeTypes" must match.
          .withIncludeExpression(".*\\.IS_VALID")

          // A Java regex matching data types to be forced to have this type.
          // 
          // Data types may be reported by your database as:
          // - NUMBER              regexp suggestion: NUMBER
          // - NUMBER(5)           regexp suggestion: NUMBER\(5\)
          // - NUMBER(5, 2)        regexp suggestion: NUMBER\(5,\s*2\)
          // - any other form.
          // 
          // It is thus recommended to use defensive regexes for types.
          // 
          // If provided, both "includeExpression" and "includeTypes" must match.
          .withIncludeTypes(".*")
      )
    )
  )
myConfigurationName(sourceSets.main) {
  generator {
    database {

      // Associate data type rewrites with database columns
      forcedTypes {
        forcedType {

          // Specify any data type that is supported in your database, or if unsupported, 
          // a type from org.jooq.impl.SQLDataType
          name = 'BOOLEAN'

          // A Java regex matching fully-qualified columns, attributes, parameters. Use the pipe to separate several expressions.
          // 
          // If provided, both "includeExpression" and "includeTypes" must match.
          includeExpression = '.*\\.IS_VALID'

          // A Java regex matching data types to be forced to have this type.
          // 
          // Data types may be reported by your database as:
          // - NUMBER              regexp suggestion: NUMBER
          // - NUMBER(5)           regexp suggestion: NUMBER\(5\)
          // - NUMBER(5, 2)        regexp suggestion: NUMBER\(5,\s*2\)
          // - any other form.
          // 
          // It is thus recommended to use defensive regexes for types.
          // 
          // If provided, both "includeExpression" and "includeTypes" must match.
          includeTypes = '.*'
        }
      }
    }
  }
}

You must provide at least either an <includeExpression/> or a <includeTypes/> element, or both.

See the section about Custom data types for rewriting columns to your own custom data types.

The jOOQ Logo