问题
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