我有以下枚举定义:

create type task_status as enum ('ok', 'fail')

一张桌子:

create table if not exists task
(
    id      uuid default gen_random_uuid() not null primary key,
    status  task_status,
    ...
);

和以下代码生成配置:

<generator>
    <name>org.jooq.codegen.JavaGenerator</name>

    <generate>
        <fluentSetters>true</fluentSetters>
        <daos>true</daos>
        <springAnnotations>true</springAnnotations>
        <springDao>true</springDao>
    </generate>

    <database>
        <name>org.jooq.meta.postgres.PostgresDatabase</name>
        <inputSchema>public</inputSchema>
        <includes>task</includes>
        <includeTables>true</includeTables>
        <includeSystemTables>false</includeSystemTables>
        <includeInvisibleColumns>false</includeInvisibleColumns>
        <includeEmbeddables>true</includeEmbeddables>
        <includeRoutines>false</includeRoutines>
        <forcedTypes>
            <forcedType>
                <name>INSTANT</name>
                <includeTypes>timestamptz</includeTypes>
            </forcedType>
        </forcedTypes>
    </database>

    <target>
        ...
    </target>
</generator>

当我运行codegen时,我得到:

public class Task implements Serializable {
    
    private Object status;
    ...
}

虽然我没有找到关于jOOQ是否真的可以从该列类型生成Java枚举类型的直接答案,但它是soundsit just works for others.我知道我可以实现定制生成器或使用枚举转换器,但我想知道Java枚举是否可以开箱即用地生成,我只是做错了.我在JOOQ3.17.13上.

推荐答案

您没有在代码生成配置中包括枚举类型:

<includes>task</includes>

取而代之的是:

<includes>task|task_status</includes>

Java相关问答推荐

JsonPath在多个线程中返回错误的值

Java自定义ThreadPool—暂停任务提交并取消当前排队任务

尽管类型擦除,instanceof与泛型在Java中如何工作?

工件部署期间出错[Tomcat 8.5.45]

关于泛型的覆盖规则

所有 case 一起输入时输出错误,而单独放置时输出正确

Spring Boot@Cachebale批注未按预期工作

Spring Boot Maven包

呈现文本和四舍五入矩形时出现的JavaFX窗格白色瑕疵

如何在ApachePOI中将图像添加到工作表的页眉?

有效的公式或值列表必须少于或等于255个字符

如何在Jooq中获取临时表列引用?

如果List是一个抽象接口,那么Collectors.toList()如何处理流呢?

对从Spring Boot 3.1.5升级到3.2.0的方法的查询验证失败

在Eclipse中可以使用外部字体吗?

接受类及其接口的Java类型(矛盾)

通过/失败的参数化junit测试方法执行数

Java编译器是否进行了持续的折叠优化,以及如何进行判断?

可以';不要在Intellij IDEA中使用最新的Java版本(JDK 21)

人们在 IntelliJ 上将-Dhttp.proxyHost=your.proxy.net -Dhttp.proxyPort=8080放在哪里?