All versions: 3.11 | 3.10 | 3.9 | 3.8 | 3.7 | Development versions: 3.12 | Unsupported versions: 3.6 | 3.5 | 3.4 | 3.3 | 3.2 | 2.6

Advanced generator configuration

In the previous section we have seen how jOOQ's source code generator is configured and run within a few steps. In this chapter we'll cover some advanced settings

jooq-meta configuration

Within the <generator/> element, there are other configuration elements:

<!-- These properties can be added to the database element: -->
<database>

  <!-- This flag indicates whether include / exclude patterns should also match
       columns within tables. -->
  <includeExcludeColumns>false</includeExcludeColumns>

  <!-- All table and view columns that are used as "version" fields for
       optimistic locking (A Java regular expression. Use the pipe to separate several expressions).
       See UpdatableRecord.store() and UpdatableRecord.delete() for details -->
  <recordVersionFields>REC_VERSION</recordVersionFields>

  <!-- All table and view columns that are used as "timestamp" fields for
       optimistic locking (A Java regular expression. Use the pipe to separate several expressions).
       See UpdatableRecord.store() and UpdatableRecord.delete() for details -->
  <recordTimestampFields>REC_TIMESTAMP</recordTimestampFields>
      
  <!-- Generate java.sql.Timestamp fields for DATE columns. This is
       particularly useful for Oracle databases.
       Defaults to false -->
  <dateAsTimestamp>false</dateAsTimestamp>

  <!-- Generate jOOU data types for your unsigned data types, which are
       not natively supported in Java.
       Defaults to true -->
  <unsignedTypes>true</unsignedTypes>

  <!-- The schema that is used in generated source code. This will be the
       production schema. Use this to override your local development
       schema name for source code generation. If not specified, this
       will be the same as the input-schema. -->
  <outputSchema>[your database schema / owner / name]</outputSchema>

  <!-- A configuration element to configure several input and/or output
       schemata for jooq-meta, in case you're using jooq-meta in a multi-
       schema environment.
       This cannot be combined with the above inputSchema / outputSchema -->
  <schemata>
    <schema>
      <inputSchema>...</inputSchema>
      <outputSchema>...</outputSchema>
    </schema>
    [ <schema>...</schema> ... ]
  </schemata>

  <!-- A configuration element to configure custom data types -->
  <customTypes>...</customTypes>

  <!-- A configuration element to configure type overrides for generated
       artefacts (e.g. in combination with customTypes) -->
  <forcedTypes>...</forcedTypes>
</database>

Check out the some of the manual's "advanced" sections to find out more about the advanced configuration parameters.

jooq-codegen configuration

Also, you can add some optional advanced configuration parameters for the generator:

<!-- These properties can be added to the generate element: -->
<generate>
  <!-- Primary key / foreign key relations should be generated and used.
       This is a prerequisite for various advanced features.
       Defaults to true -->
  <relations>true</relations>

  <!-- Generate deprecated code for backwards compatibility
       Defaults to true -->
  <deprecated>true</deprecated>

  <!-- Generate instance fields in your tables, as opposed to static
       fields. This simplifies aliasing.
       Defaults to true -->
  <instanceFields>true</instanceFields>

  <!-- Generate the javax.annotation.Generated annotation to indicate
       jOOQ version used for source code.
       Defaults to true -->
  <generatedAnnotation>true</generatedAnnotation>

  <!-- Generate jOOQ Record classes for type-safe querying. You can
       turn this off, if you don't need "active records" for CRUD
       Defaults to true -->
  <records>true</records>

  <!-- Generate POJOs in addition to Record classes for usage of the
       ResultQuery.fetchInto(Class) API
       Defaults to false -->
  <pojos>false</pojos>

  <!-- Generate immutable POJOs for usage of the ResultQuery.fetchInto(Class) API
       This overrides any value set in <pojos/>
       Defaults to false -->
  <immutablePojos>false</immutablePojos>

  <!-- Generate interfaces that will be implemented by records and/or pojos.
       You can also use these interfaces in Record.into(Class<?>) and similar
       methods, to let jOOQ return proxy objects for them.
       Defaults to false -->
  <interfaces>false</interfaces>

  <!-- Generate DAOs in addition to POJO classes
       Defaults to false -->
  <daos>false</daos>

  <!-- Annotate POJOs and Records with JPA annotations for increased
       compatibility and better integration with JPA/Hibernate, etc
       Defaults to false -->
  <jpaAnnotations>false</jpaAnnotations>

  <!-- Annotate POJOs and Records with JSR-303 validation annotations
       Defaults to false -->
  <validationAnnotations>false</validationAnnotations>
  
  <!-- Allow to turn off the generation of global object references, which include
  
       - Tables.java
       - Sequences.java
       - UDTs.java
  
       Turning off the generation of the above files may be necessary for very
       large schemas, which exceed the amount of allowed constants in a class's
       constant pool (64k) or, whose static initialiser would exceed 64k of
       byte code
       
       Defaults to true -->
  <globalObjectReferences>true</globalObjectReferences>
  
  <!-- Generate fluent setters in
  
       - records
       - pojos
       - interfaces
       
       Fluent setters are against the JavaBeans specification, but can be quite
       useful to those users who do not depend on EL, JSP, JSF, etc.
       
       Defaults to false -->
  <fluentSetters>false</fluentSetters>
</generate>

Property interdependencies

Some of the above properties depend on other properties to work correctly. For instance, when generating immutable pojos, pojos must be generated. jOOQ will enforce such properties even if you tell it otherwise. Here is a list of property interdependencies:

  • When daos = true, then jOOQ will set relations = true
  • When daos = true, then jOOQ will set records = true
  • When daos = true, then jOOQ will set pojos = true
  • When immutablePojos = true, then jOOQ will set pojos = true
The jOOQ Logo