Anyone know how to deal with `"Can't init value ou...
# exposed
c
Anyone know how to deal with
"Can't init value outside the transaction"
error message? my intention was to take the entity Lecture with join Educator entity like
Copy code
return Lecture.findById(id)?.load(Lecture::educator) ?: throw Exception("Lecture not found")
@Transactional
annotation is applied to above sentence function and then if i want to use result of above query outside of transactional function. error occurs. So, i treated this issue with this way, define
LectureAggregate
,
Copy code
data class LectureAggregate(
    val id: Long,
    val createdAt: LocalDateTime,
    val updatedAt: LocalDateTime,
    val name: String,
    val status: LectureStatus,
    val registrationCode: String,
    val educator: EducatorAggregate
) {
    data class EducatorAggregate(
        val id: Long,
        val createdAt: LocalDateTime,
        val updatedAt: LocalDateTime,
        val name: String
    )

    constructor(lecture: Lecture) : this(
        id = lecture.id.value,
        createdAt = lecture.createdAt,
        updatedAt = lecture.updatedAt,
        name = lecture.name,
        status = lecture.status,
        registrationCode = lecture.registrationCode,
        educator = EducatorAggregate(
            id = lecture.educator.id.value,
            createdAt = lecture.educator.createdAt,
            updatedAt = lecture.educator.updatedAt,
            name = lecture.educator.name
        )
    )
}
and assign the result of query to
LectureAggregate
. In this way, i can avoid the error and can use LectureAggregate freely outside of transaction function. But i think it is temporary solution. anyone has better solution for this problem?
https://github.com/JetBrains/Exposed/tree/main/exposed-spring-boot-starter#configuring-exposed i followed above instruction to resolve this issue, but
"Can't init value outside the transaction"
error keeps occuring. why
keepLoadedReferencesOutOfTransaction
options doesn’t work??? for infornation, in the test code i manually connect with databse config option with
keepLoadedReferencesOutOfTransaction
, it works