Hello I want to report a bug. I have an hibernate entity that is returning NPE for the delegated fields.
---- BaseUser.kt ----
@Entity
@Table("base_user")
@Inheritance(strategy = JOINED)
abstract class BaseUser(
id: Long,
@OneToOne
@JoinColumn(name = "base_user_id", referencedColumnName = "id", nullable = false, unique = true)
private val user User
) BaseModel(id) { val email: String by user }
---- User.kt ----
@Entity
@Table("user")
data class User(
@Id val id: Long,
var email: String
) {
operator fun <T> getValue(user: User, property: KProperty<*>) : T {
return User::class.declaredMemberProperties.first { it.name == property.name }.get(this) as T
}
}
When I get this entity from the DB the email is null and the email$delegate throws NPE. Checking the decompiled java code I see that it has a non-args constructor which is not setting the delegate behaviour.
---- BaseUser.decompiled.java ----
public BaseUser(long id, @NotNull User user) {
Intrinsics.checkParameterIsNotNull(user, "user");
super(id);
this.user = user;
this.email$delegate = this.user;
}
public BaseUser() {
}