我正在使用:
我能够生成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类型。我不确定要更改什么才能解决此问题。
谢谢
您可能应该将所有这些ID
列的类型及其引用更改为相同,即BIGINT
。
作为一种快速的解决方法,您可以使用Field.coerce()
。我更喜欢Field.coerce()
。区别在于Field.cast()
对生成的SQL没有任何影响(您希望避免这种情况以获得更好的索引使用率),而Field.cast()
转换为SQL coerce()
函数。