In my entity, I initialize some fields in a constructor. (with plugins, this class has a no-args constructor and the class and all members are open using jpa plugin and all-open)
@Entity
class Bike {
@Id
val id: String
var available: Boolean
protected set
@Suppress("ConvertSecondaryConstructorToPrimary", "LeakingThis")
constructor(id: String) {
this.id = id
this.available = true
}
}
If I disable all-open for this class, Hibernate demands that my properties are open, so it can inject some proxies for lazy initialization (prints ERROR log).
Turns out, I am assigning a value to open property in a constructor, which gives me an IDE warning.
I tried to research on that and I just can’t possibly find any issue with properties. Can you give me an example? I saw the example from an IDE when you call a method in a base class that uses a property from a child, but that’s not about properties.
In the Kotlin Hibernate tutorials (like Hibernate with Kotlin - powered by Spring Boot - Kotlin Expertise Blog) they just use primary constructors, but that is exactly the same thing, I don’t even understand why the warning goes away. In my code, I use secondary constructor just because it is easier to place annotations on the constructor, but I can just make it primary and it goes away.
Right now I am ignoring this warning, I think Hibernate won’t be doing any bad stuff with my properties since it’s all just proxies.
Please, let me know what you think, thanks!