简体   繁体   中英

Jooq 3.9 doesn't link MySQL columns to enums

I am updating jooq from version 3.4.1 to 3.9.3 and noticed that models for tables that have enum fields in MySQL 5.6 database are generated with String type instead.

The enum corresponding to the field is properly generated, it's just not linked to the pojo corresponding to the table.

CREATE TABLE foo (
  bar ENUM('BarBar') NOT NULL
}

This is an example of generated Pojo for the table Foo :

@Generated(
    value = {
        "http://www.jooq.org",
        "jOOQ version:3.9.0"
    },
    comments = "This class is generated by jOOQ"
)
public class Foo {
    private String bar;
}

and the enum which is not linked to the table pojo, although in its name contains Foo prefix of the table:

@Generated(
    value = {
        "http://www.jooq.org",
        "jOOQ version:3.9.0"
    },
    comments = "This class is generated by jOOQ"
)
public enum FooBar implements EnumType {

    BarBar("BarBar");

    private final String literal;

    // ...
}

I haven't changed any configuration, just jooq version. I would like to know if this is a bug or most likely some piece of configuration missing on my side.

This change was introduced between versions 3.8.8 and 3.9.0 but i haven't been able to narrow it down from release notes.

There is an issue that sort of corresponds to this but it shouldn't have went live, so it's possibly outdated configuration on my part.

There are two reasons why this could happen:

A bug in jOOQ related to <outputSchemaToDefault/>

This looks like bugs

  • #6367 - PostgreSQL enums aren't linked correctly from generated tables when <outputSchemaToDefault/> is true
  • #6395 - Definition.getQualifiedName() is wrong when <outputSchemaToDefault/> is set to true

Which will be fixed in jOOQ 3.10.0, 3.9.4, 3.8.8. The issue is related to setting the <outputSchemaToDefault/> flag to true.

You're excluding the enum type with your configuration

The <includes/> and <excludes/> configuration must ensure that the enum type is included as code generation output. The enum type is a synthetic type that behaves like a PostgreSQL enum type. It has a synthetic name that is made from: [TABLE_NAME]_[COLUMN_NAME] .

Note: In your case, I'm assuming this is done correctly, because you're getting the enum type itself. I'm adding this here for completeness' sake, in case someone else has similar issues.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM