Search code examples
sqltypesjooqjooq-codegen-maven

Jooq text array generated as object array


given the following sql

create table something(
  id BIGSERIAL,
  something TEXT[] NOT NULL DEFAULT '{}',
  PRIMARY KEY (id)
);

and instructing the code generator to use DDLDatabase the generated item is in the form of

    public final TableField<JSomethingRecord, Object[]> SOMETHING_

Looking around in the documentation I cannot find how can this be mapped in a String[]. same applies for varchar and varchar(255). I shouldn't have to use an enforced type here as at least on of the three should be a valid datatype and not fallback to OTHER as it happens with the UUID (for which I saw there is an example for enforced types)

Am I doing / understanding something wrong or this is an expected behaviour?

The database I am using is PostGres and the generator configuration is the following

<generator>
    <database>
        <name>org.jooq.meta.extensions.ddl.DDLDatabase</name>
        <inputCatalog/>
        <inputSchema>PUBLIC</inputSchema>
        <properties>
            <property>
                <key>use-attribute-converters</key>
                <value>true</value>
            </property>
            <property>
                <key>scripts</key>
                <value>src/main/resources/db/migration/*</value>
            </property>
        </properties>
    </database>
    <target>
        <clean>true</clean>
        <packageName>my.other.package</packageName>
        <directory>target/generated-sources/jooq</directory>
    </target>
</generator>

Thank you in advance


Solution

  • As of jOOQ 3.13, PostgreSQL's typed arrays are not yet supported by the DDLDatabase, because the current implementation of the DDLDatabase translates your DDL to H2 behind the scenes, and H2 1.4.200's ARRAY type does not support any other type of array than Object[].

    This will change in the future, as:

    1. H2 1.4.201 will support typed arrays like PostgreSQL: https://github.com/h2database/h2database/issues/1390
    2. jOOQ will support running your DDL on an actual PostgreSQL database in test containers: https://github.com/jOOQ/jOOQ/issues/6551
    3. jOOQ will support interpreting the DDL instead of running it on a third party database product: https://github.com/jOOQ/jOOQ/issues/7034

    Until then, in order to use such PostgreSQL-specific features, I recommend using the classic approach of connecting to an actual PostgreSQL database instance.