我正在将一个 java 项目转换为 kotlin,但在使用查询结果构造数据对象时出错。查询是在 Docs 和 Questions 之间具有一对多关系的联接。这适用于java,但我无法让它与kotlin一起使用。我尝试过提供默认值并使用 no-args 项目。不确定这是 kotlin、jooq 还是简单的平面映射器问题。
Spring boot: 2.5.4
kotlin: 1.5.31
implementation 'org.simpleflatmapper:sfm-jooq:8.2.3'
implementation 'org.springframework.boot:spring-boot-starter-jooq'
@Repository
open class DocRepository(private val dslContext: DSLContext) {
companion object : KLogging()
private val docMapper = SelectQueryMapperFactory.newInstance().newMapper(
Doc::class.java
)
override fun getDocDetails(docId: Int): Doc {
return docMapper.asList(
dslContext.select(
Tables.DOC.DOC_ID,
Tables.DOC.TITLE,
Tables.DOC.DESCRIPTION,
Tables.DOC.QUESTION.QUESTION_ID,
Tables.DOC.QUESTION.DOC_ID,
Tables.DOC.QUESTION.QUESTION,
Tables.DOC.QUESTION.ANSWER
)
.from(Tables.DOC).leftJoin(Tables.QUESTION)
.on(Tables.QUESTION.DOC_ID.eq(Tables.DOC.DOC_ID))
.where(Tables.DOC.DOC_ID.eq(docId))
).stream().findFirst().get()
}
}
data class Doc(
var docId: Int? = null,
val title: String? = "",
val description: String? = "",
var questions: List<Question?>? = null,
)
data class Question(
var questionId: Int? = null,
var docId: Int? = null,
var question: String? = "",
var answer: String? = ""
)
org.jooq.exception.MappingException: No constructor available for class com.test.entity.Doc
at org.simpleflatmapper.jooq.SelectQueryMapper.getMapper(SelectQueryMapper.java:186)
at org.simpleflatmapper.jooq.SelectQueryMapper.asList(SelectQueryMapper.java:46)