New versions: Dev (3.14) | Latest (3.13) | 3.12 | 3.11 | 3.10

DDLDatabase: Code generation from SQL files

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

In many cases, the schema is defined in the form of a SQL script, which can be used with Flyway, or some other database migration tool.

If you have a complete schema definition in a single file, or perhaps a set of incremental files that can reproduce your schema in any SQL dialect, then the DDLDatabase might be the right choice for you. It uses the SQL parser internally and applies all your DDL increments to an in-memory H2 database, in order to produce a replica of your schema prior to reverse engineering it again using ordinary code generation.

For example, the following database.sql script (the sample database from this manual) could be used:

CREATE TABLE language (
  id              NUMBER(7)     NOT NULL PRIMARY KEY,
  cd              CHAR(2)       NOT NULL,
  description     VARCHAR2(50)

  id              NUMBER(7)     NOT NULL PRIMARY KEY,
  first_name      VARCHAR2(50),
  last_name       VARCHAR2(50)  NOT NULL,
  date_of_birth   DATE,
  year_of_birth   NUMBER(7),
  distinguished   NUMBER(1)

  id              NUMBER(7)     NOT NULL PRIMARY KEY,
  author_id       NUMBER(7)     NOT NULL,
  title           VARCHAR2(400) NOT NULL,
  published_in    NUMBER(7)     NOT NULL,
  language_id     NUMBER(7)     NOT NULL,
  CONSTRAINT fk_book_author     FOREIGN KEY (author_id)   REFERENCES author(id),
  CONSTRAINT fk_book_language   FOREIGN KEY (language_id) REFERENCES language(id)

CREATE TABLE book_store (
  name            VARCHAR2(400) NOT NULL UNIQUE

CREATE TABLE book_to_book_store (
  name            VARCHAR2(400) NOT NULL,
  book_id         INTEGER       NOT NULL,
  stock           INTEGER,
  PRIMARY KEY(name, book_id),
  CONSTRAINT fk_b2bs_book_store FOREIGN KEY (name)        REFERENCES book_store (name) ON DELETE CASCADE,
  CONSTRAINT fk_b2bs_book       FOREIGN KEY (book_id)     REFERENCES book (id)         ON DELETE CASCADE

While the script uses pretty standard SQL constructs, you may well use some vendor-specific extensions, and even DML statements in between to set up your schema - it doesn't matter. You will simply need to set up your code generation configuration as follows:

XML configuration (standalone and Maven)

<configuration xmlns="">
        <!-- Specify the location of your SQL script.
             You may use ant-style file matching, e.g. /path/**/to/*.sql
             - ** matches any directory subtree
             - * matches any number of characters in a directory / file name
             - ? matches a single character in a directory / file name
        <!-- The sort order of the scripts within a directory, where:
             - semantic: sorts versions, e.g. v-3.10.0 is after v-3.9.0 (default)
             - alphanumeric: sorts strings, e.g. v-3.10.0 is before v-3.9.0
             - none: doesn't sort directory contents after fetching them from the directory

Programmatic configuration

new org.jooq.meta.jaxb.Configuration()
  .withGenerator(new Generator(
    .withDatabase(new Database()
        new Property()
        new Property()

Gradle configuration

myConfigurationName(sourceSets.main) {
  generator {
    database {
      name = 'org.jooq.meta.extensions.ddl.DDLDatabase'
      properties {
        property {
          key = 'scripts'
          value = 'src/main/resources/database.sql'
        property {
          key = 'sort'
          value = 'semantic'


Note that the org.jooq.meta.extensions.ddl.DDLDatabase class is located in an external dependency, which needs to be placed on the classpath of the jOOQ code generator. E.g. using Maven:

  <!-- Use org.jooq            for the Open Source Edition
         for commercial editions, 
  for commercial editions with Java 8 support,
  for commercial editions with Java 6 support,
           org.jooq.trial      for the free trial edition 
       Note: Only the Open Source Edition is hosted on Maven Central. 
             Import the others manually from your distribution -->
The jOOQ Logo