I’m converting a java project to kotlin but getting an error constructing a data object with the query results. The query is a join with a one to many relationship between Docs and Questions. This works in java but I can’t get it to work with kotlin. I’ve tried providing default values and using the no-args project. Not sure if this is a kotlin, jooq, or simple flat mapper issue.
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)