简体   繁体   中英

JOOQ throws DataTypeException when fetching table meta

Getting an error when trying to fetch table meta data.

Using: JOOQ 3.14.0, PostgeSQL 12, PostgreSQL driver 42.2.10

Example:

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

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

Error (This is not the whole error but the rest is similar):

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$4.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$4.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)
    

Example table create script :

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;

Initially my goal was to get the table indexes and this is working fine. I tried to update JOOQ from 3.13.1 to 3.14.0 and tested with different tables in the database but without any luck.

This is a bug which will be fixed in jOOQ 3.15 via https://github.com/jOOQ/jOOQ/issues/8469 . jOOQ currently assumes that DatabaseMetaData column descriptions produce values for DEFAULT expressions, instead of expressions.

The bug is "cosmetic", as it only affects your logs. The field is still produced correctly (without any DEFAULT expression). You can mute the message in your logger configuration until the above bug is fixed.

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