Hi, I have an issue with transient fields not bein...
# announcements
p
Hi, I have an issue with transient fields not being initialized after jpa saves the entity and get the value back. The reason of this is that kotlin is generating a default constructur with no params that calls super() when there is at least 1 constructor field without default value. If I define defaults to all my field in the primary constructor, then kotlin is not generation the default constructor with no params calling super() ans hence my transient field is being initialized well data class Person( var name: String){ @transient private val id: MyId = MyId() // after repo.save(person); this is not being initialized. id is null } fix data class Person( var name: String = “”){ //creating default values fix the problem @transient private val id: MyId = MyId() } Is this a bug?
r
There is an option, invokeInitializers, that may help.
p
It worked! thanks!
solution: in my gradle file:
Copy code
plugins {
    id("org.jetbrains.kotlin.plugin.noarg")
}

configure<org.jetbrains.kotlin.noarg.gradle.NoArgExtension> {
    annotation("com.example.DefaultConstructor")
    invokeInitializers = true
}
and then in my data class @DefaultConstructor data class Person( var name: String){ @transient private val id: MyId = MyId() }