JOOQ 在获取 table 元时抛出 DataTypeException

JOOQ throws DataTypeException when fetching table meta

尝试获取 table 元数据时出错。

使用: JOOQ 3.14.0, PostgeSQL 12, PostgreSQL 驱动程序 42.2.10

示例:

@RestController
@ApiVersion("v2")
public class TypeResource {
    private final DSLContext ctx;

    @GetMapping(value = "/test")
    public void test(@RequestParam String table) {
        ctx.meta().getTables(table);
    }
}

错误(这不是全部错误,其余类似):

17:16:44.808 [http-nio-8181-exec-5] [WARN ] org.jooq.impl.MetaImpl - Default value            : Could not load default value: '{}'::character varying[] for type: varchar ([Ljava.lang.String;)
org.jooq.exception.DataTypeException: Cannot convert from '{}'::character varying[] (class java.lang.String) to class [Ljava.lang.String;
    at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1303)
    at org.jooq.tools.Convert$ConvertAll.from(Convert.java:1192)
    at org.jooq.tools.Convert.convert0(Convert.java:392)
    at org.jooq.tools.Convert.convert(Convert.java:384)
    at org.jooq.tools.Convert.convert(Convert.java:458)
    at org.jooq.impl.AbstractDataType.convert(AbstractDataType.java:534)
    at org.jooq.impl.DefaultDataType.convert(DefaultDataType.java:86)
    at org.jooq.impl.DSL.val(DSL.java:24373)
    at org.jooq.impl.DSL.inline(DSL.java:23891)
    at org.jooq.impl.MetaImpl$MetaTable.init(MetaImpl.java:910)
    at org.jooq.impl.MetaImpl$MetaTable.<init>(MetaImpl.java:560)
    at org.jooq.impl.MetaImpl$MetaSchema.getTables(MetaImpl.java:421)
    at org.jooq.impl.MetaImpl.getTables0(MetaImpl.java:217)
    at org.jooq.impl.AbstractMeta.iterator(AbstractMeta.java:194)
    at org.jooq.impl.AbstractMeta.get(AbstractMeta.java:340)
    at org.jooq.impl.AbstractMeta.initTables(AbstractMeta.java:191)
    at org.jooq.impl.AbstractMeta.getTables(AbstractMeta.java:172)
    at org.jooq.impl.AbstractMeta.getTables(AbstractMeta.java:167)
17:16:44.843 [http-nio-8181-exec-5] [WARN ] org.jooq.impl.MetaImpl - Default value            : Could not load default value: '{{0,0}}'::numeric[] for type: numeric ([Ljava.math.BigDecimal;)
org.jooq.exception.DataTypeException: Cannot convert from '{{0,0}}'::numeric[] (class java.lang.String) to class [Ljava.math.BigDecimal;
    at org.jooq.tools.Convert$ConvertAll.fail(Convert.java:1303)
    at org.jooq.tools.Convert$ConvertAll.from(Convert.java:1192)
    at org.jooq.tools.Convert.convert0(Convert.java:392)
    at org.jooq.tools.Convert.convert(Convert.java:384)
    at org.jooq.tools.Convert.convert(Convert.java:458)
    at org.jooq.impl.AbstractDataType.convert(AbstractDataType.java:534)
    at org.jooq.impl.DefaultDataType.convert(DefaultDataType.java:86)
    at org.jooq.impl.DSL.val(DSL.java:24373)
    at org.jooq.impl.DSL.inline(DSL.java:23891)
    at org.jooq.impl.MetaImpl$MetaTable.init(MetaImpl.java:910)
    at org.jooq.impl.MetaImpl$MetaTable.<init>(MetaImpl.java:560)
    at org.jooq.impl.MetaImpl$MetaSchema.getTables(MetaImpl.java:421)
    at org.jooq.impl.MetaImpl.getTables0(MetaImpl.java:217)
    at org.jooq.impl.AbstractMeta.iterator(AbstractMeta.java:194)
    at org.jooq.impl.AbstractMeta.get(AbstractMeta.java:340)
    at org.jooq.impl.AbstractMeta.initTables(AbstractMeta.java:191)
    at org.jooq.impl.AbstractMeta.getTables(AbstractMeta.java:172)
    at org.jooq.impl.AbstractMeta.getTables(AbstractMeta.java:167)
    

示例 table 创建脚本:

CREATE TABLE public.user_role
(
    id bigint NOT NULL DEFAULT nextval('user_role_id_seq'::regclass),
    user_id bigint NOT NULL,
    role_id bigint NOT NULL,
    ts_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    ts_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP,
    updated_by_user character varying(256) COLLATE pg_catalog."default" NOT NULL DEFAULT 'n/a'::character varying,
    updated_by_process character varying(64) COLLATE pg_catalog."default" NOT NULL DEFAULT 'n/a'::character varying,
    CONSTRAINT user_role_pkey PRIMARY KEY (id),
    CONSTRAINT x_role_id_fk FOREIGN KEY (role_id)
        REFERENCES public.role (id) MATCH FULL
        ON UPDATE NO ACTION
        ON DELETE NO ACTION,
    CONSTRAINT x_user_id_fk FOREIGN KEY (user_id)
        REFERENCES public."user" (id) MATCH FULL
        ON UPDATE NO ACTION
        ON DELETE NO ACTION
)

TABLESPACE pg_default;

ALTER TABLE public.user_role
    OWNER to postgres;

CREATE UNIQUE INDEX x_role_user_id_role_id_uq
    ON public.user_role USING btree
    (user_id ASC NULLS LAST, role_id ASC NULLS LAST)
    TABLESPACE pg_default;

最初我的目标是获取 table 索引,这工作正常。 我尝试将 JOOQ 从 3.13.1 更新到 3.14.0,并在数据库中使用不同的 table 进行了测试,但没有任何运气。

这是一个错误,将通过 https://github.com/jOOQ/jOOQ/issues/8469 在 jOOQ 3.15 中修复。 jOOQ 目前假定 DatabaseMetaData 列描述为 DEFAULT 表达式而不是表达式生成值。

该错误是“装饰性的”,因为它只影响您的日志。该字段仍然正确生成(没有任何 DEFAULT 表达式)。在修复上述错误之前,您可以在记录器配置中静音消息。