I did not understand.
# announcements
t
I did not understand.
r
To fill a new object, JPA needs public constructor which doesn't have any argument. Even though you've set default values for your data class properties, from Java point of view that's still one constructor with multiple arguments.
r
There are two ways to solve this issue for you. 1. You can either add
@JvmOverloads
annotation on method (constructor in your case) with default arguments on Kotlin side. This will generate one additional method for each substituted default value on Java side. I.e. for
data class C @JvmOverloads constructor(val a: Int = 5, val b: String = "Hello!")
there would be constructors with two, one and zero arguments. That's not really the thing you want probably. 2. Add
no-arg
plugin mentioned to answers. Look through the https://kotlinlang.org/docs/reference/compiler-plugins.html#no-arg-compiler-plugin -- it mentions that this plugin specifically creates additional no-arg constructor for JPA to consume. After calling it, JPA will fill your values as fields.
t
Thank you.