"no suitable method found" 在尝试实现自定义绑定时

"no suitable method found" while trying to implement a custom binding

我在尝试为 Postgres ltrees 创建自定义绑定时收到以下消息:

[...]/jooq/routines/JSubpath1.java:37: error: no suitable method found for createParameter(String,DataType<Integer>,boolean,boolean,LtreeBinding)
    public static final Parameter<String> _2 = Internal.createParameter("_2", org.jooq.impl.SQLDataType.INTEGER, false, true, new LtreeBinding());
                                                       ^
    method Internal.<T#1>createParameter(String,DataType<T#1>,boolean,boolean) is not applicable
      (cannot infer type-variable(s) T#1
        (actual and formal argument lists differ in length))
    method Internal.<T#2,U#1>createParameter(String,DataType<T#2>,boolean,boolean,Converter<T#2,U#1>) is not applicable
      (cannot infer type-variable(s) T#2,U#1
        (argument mismatch; LtreeBinding cannot be converted to Converter<T#2,U#1>))
    method Internal.<T#3,U#2>createParameter(String,DataType<T#3>,boolean,boolean,Binding<T#3,U#2>) is not applicable
      (inference variable T#3 has incompatible equality constraints Object,Integer)
    method Internal.<T#4,X,U#3>createParameter(String,DataType<T#4>,boolean,boolean,Converter<X,U#3>,Binding<T#4,X>) is not applicable
      (cannot infer type-variable(s) T#4,X,U#3
        (actual and formal argument lists differ in length))

绑定如下:

class LtreeBinding : Binding<Any, String> {

    override fun converter(): Converter<Any, String> {
        return object : Converter<Any, String> {
            override fun from(dbAny: Any?): String? {
                return dbAny?.toString()
            }

            override fun to(userAny: String?): Any? {
                return userAny as Any
            }

            override fun fromType(): Class<Any> {
                return Any::class.java
            }

            override fun toType(): Class<String> {
                return String::class.java
            }
        }
    }

    override fun sql(ctx: BindingSQLContext<String>) {
        ctx.render()?.let {
            if (it.paramType() == ParamType.INLINED) {
                it.visit(
                    DSL.inline(ctx.convert(converter()).value())
                )
            } else {
                it.sql("?")
            }
        }
    }

    override fun register(ctx: BindingRegisterContext<String>) {
        ctx.statement().registerOutParameter(ctx.index(), Types.VARCHAR)
    }

    override fun set(ctx: BindingSetStatementContext<String>) {
        ctx.statement().setString(
            ctx.index(),
            ctx.convert(converter()).value()?.toString()
        )
    }

    override fun set(ctx: BindingSetSQLOutputContext<String>) {
        throw SQLFeatureNotSupportedException()
    }

    override fun get(ctx: BindingGetResultSetContext<String>) {
        ctx.convert(converter()).value(ctx.resultSet().getString(ctx.index()))
    }

    override fun get(ctx: BindingGetStatementContext<String>) {
        ctx.convert(converter()).value(ctx.statement().getString(ctx.index()))
    }

    override fun get(ctx: BindingGetSQLInputContext<String>) {
        throw SQLFeatureNotSupportedException()
    }
}

生成器配置在 XML 中的 Gradle“构建”文件中完成。生成的代码位于 src/main/java/generated 内,而其余代码(包括绑定)位于 src/main/kotlin.

有什么问题吗?错误日志并没有给我任何线索。

生成的代码如下:

Internal.createParameter("_2", SQLDataType.INTEGER, false, true, new LtreeBinding());

这意味着你的参数的数据类型是INTEGER,而不是OTHER。所以你的绑定不能是 Binding<Any, String> 类型。可能,您的绑定只是应用于存储函数的错误参数。

如果您控制该函数,请确保它使用命名参数,以便您可以按名称将绑定附加到正确的参数。否则,您可以尝试使用 <includeTypes/> as documented here.

按类型将其附加到正确的参数