Datatypes incompatible when using sql custom routine with jooq

廉价感情. 提交于 2020-04-18 06:12:20

问题


While implementing an upsert that uses a custom-defined SQL function, I came across the following error:

[ERROR] /home/user/company/ahqjava/sql/src/main/java/com/company/project/sql/daos/ExampleDAO.java:[60,56] no suitable method found for mergeData(org.jooq.TableField<com.company.project.sql.jooq.tables.records.ExampleRecord,java.util.Map<java.lang.String,java.lang.String>>,java.util.Map<java.lang.String,java.lang.String>)[ERROR]     method com.company.project.sql.jooq.Routines.mergeData(java.util.Map<java.lang.String,java.lang.String>,java.util.Map<java.lang.String,java.lang.String>) is not applicable
[ERROR]       (argument mismatch; org.jooq.TableField<com.company.project.sql.jooq.tables.records.ExampleRecord,java.util.Map<java.lang.String,java.lang.String>> cannot be converted to java.util.Map<java.lang.String,java.lang.String>)
[ERROR]     method com.company.project.sql.jooq.Routines.mergeData(org.jooq.Field<java.util.Map<java.lang.String,java.lang.String>>,org.jooq.Field<java.util.Map<java.lang.String,java.lang.String>>) is not applicable
[ERROR]       (argument mismatch; java.util.Map<java.lang.String,java.lang.String> cannot be converted to org.jooq.Field<java.util.Map<java.lang.String,java.lang.String>>)

The custom SQL function merge_data() looks like this:

CREATE OR REPLACE FUNCTION merge_data(left_data hstore, right_data hstore)
  RETURNS HSTORE AS $$
    SELECT (left_data || right_data)
     $$
   LANGUAGE SQL;

and this is the current jooq DSL

return DSL.using(configuration)
        .insertInto(EXAMPLE)
        .columns(EXAMPLE.EXAMPLE_ID, EXAMPLE.EXAMPLE_DATA)
        .values(EXAMPLE.getExampleId(), example.getExampleData())
        .onDuplicateKeyUpdate()
        .set(EXAMPLE.EXAMPLE_DATA, Routines.mergeData(EXAMPLE.EXAMPLE_DATA, example.getExampleData())

        )
       .execute();

Example example is a POJO.

For the sake of completeness, this is the method I'm using to call the function:

    @Test
    public void upsertTestDifferentExampleData() {
        Example example = createExample();
        jooq.transaction(cfg -> {

            dao.upsert(example, cfg);

        });


    }

Can someone suggest an approach to get rid of this parameter clash?

Edit: Here's my forced type config

types.add(new ForcedType()
                .withUserType("java.util.Map<String, String>")
                .withBinding("HStoreStringBinding")
                .withIncludeExpression(".*_data.*")
                .withIncludeTypes(".*"));

        types.add(new ForcedType()
                .withUserType("java.util.Map<String, Long>")
                .withBinding("HStoreLongBinding")
                .withIncludeExpression(".*_counts")
                .withIncludeTypes(".*"));

来源:https://stackoverflow.com/questions/61224353/datatypes-incompatible-when-using-sql-custom-routine-with-jooq

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!