【发布时间】:2020-09-04 02:29:06
【问题描述】:
我正在使用:
- Jooq 3.13.2
- Kotlin 1.3.71
- Spring Boot 2.2.6.RELESE
- Java 11
我能够生成 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 类型。我不确定需要进行哪些更改才能解决此问题。
谢谢
【问题讨论】:
-
CREATED_BY 字段的生成类型是什么?
-
嗨@LiorH,正如在问题的编辑部分中发布的那样,看起来问题是因为 id 是整数,而 created_by 在数据库中是 biginteger(导致生成的代码对于 id 是整数,对于 createdBy 是 long )。我想我找到了一个使用强制转换方法的临时解决方案:
.leftJoin(USERS).on(USERS.ID.cast(Long::class.java).eq(STORY.CREATED_BY))我认为更好的解决方案是对齐数据库中的类型。我想我最终会这样做。