我收到以下消息,试图为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()
}
}
生成器配置是通过Gradle“构建”文件中的XML完成的。生成的代码位于src/main/java/generated
内部,而其余代码(包括绑定)位于src/main/kotlin
中。
可能是什么问题?错误日志并没有给我任何线索。
答案 0 :(得分:2)
生成的代码为:
Internal.createParameter("_2", SQLDataType.INTEGER, false, true, new LtreeBinding());
这意味着参数的数据类型为INTEGER
,而不是OTHER
。因此,您的绑定不能为Binding<Any, String>
类型。可能是您的绑定只是简单地应用于存储函数的错误参数。
如果控制该函数,请确保它使用命名参数,以便可以按名称将绑定附加到正确的参数。否则,您可以尝试使用<includeTypes/>
as documented here通过类型将其附加到正确的参数。