javapostgresqljooq

Is there a way to have code generator generate a list of constants for all table names and columns?


I need to use table name/column names in annotations so they must be constant (can't call TABLE1.getName()).

Is there a way to have Jooq code generator generate these automatically in the format of public static final String TABLE1 = "table1"

and similarly for columns inside each table?


Solution

  • In jOOQ 3.19+, you can enable globalObjectNames in the code generator: https://www.jooq.org/doc/latest/manual/code-generation/codegen-advanced/codegen-config-generate/codegen-generate-global-object-names/

    Here's how to configure it with Maven

    <configuration>
      <generator>
        <generate>
          <globalObjectNames>true</globalObjectNames>
        </generate>
      </generator>
    </configuration>
    

    Or Gradle:

    configuration {
      generator {
        generate {
          isGlobalObjectNames = true
        }
      }
    }