【发布时间】:2020-10-27 19:28:34
【问题描述】:
我在尝试为 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。
可能出了什么问题?错误日志并没有真正给我任何线索。
【问题讨论】:
-
您的代码生成器和类路径上的运行时库的版本是否匹配?
-
是的。所有这些都设置为 3.13.5。 @LukasEder
标签: jooq