我正在使用:
我能够生成Jooq类并执行一个简单的查询:
class StoryCustomRepositoryImpl @Autowired constructor(
private val dslContext: DSLContext
): StoryCustomRepository {
override fun findEmployeeStories(pageable: Pageable) {
return dslContext.select(STORY.ID, STORY.DESCRIPTION)
.from(STORY)
.forEach { println($it[STORY.ID]) }
}
}
当我尝试通过添加连接来添加更复杂的逻辑时,编译失败:
class StoryCustomRepositoryImpl @Autowired constructor(
private val dslContext: DSLContext
): StoryCustomRepository {
override fun findEmployeeStories(pageable: Pageable) {
return dslContext.select(STORY.ID, STORY.DESCRIPTION)
.from(STORY)
.join(USERS).on(USERS.ID.eq(STORY.CREATED_BY))
.forEach { println($it[STORY.ID]) }
}
}
在下面的第.join(USERS).on(USERS.ID.eq(STORY.CREATED_BY))
行上编译失败
错误:
None of the following functions can be called with the arguments supplied:
public abstract fun eq(p0: Int!): Condition! defined in org.jooq.TableField
public abstract fun eq(p0: Field<Int!>!): Condition! defined in org.jooq.TableField
public abstract fun eq(p0: QuantifiedSelect<out Record1<Int!>!>!): Condition! defined in org.jooq.TableField
public abstract fun eq(p0: Select<out Record1<Int!>!>!): Condition! defined in org.jooq.TableField
我正在关注本教程:https://blog.jooq.org/2017/05/18/10-nice-examples-of-writing-sql-in-kotlin-with-jooq/
编辑: 看起来问题在于STORY.CREATED_BY是Long类型,而USERS.ID是Integer类型。我不确定要更改什么才能解决此问题。
谢谢
答案 0 :(得分:0)
您可能应该将所有这些ID
列的类型及其引用更改为相同,即BIGINT
。
作为一种快速的解决方法,您可以使用Field.coerce()
。我更喜欢Field.cast()
。区别在于coerce()
对生成的SQL没有任何影响(要避免使用该索引以获得更好的索引使用),而cast()
转换为SQL CAST()
函数。>