It means the `@Id` should be `var` and nullable ty...
# server
d
It means the
@Id
should be
var
and nullable type? I should every time write
val id = entity.id!!
in this case. I hope JBoss team will do improvement for Kotlin in the future (for Hibernate).
m
hi there probably this message is good to start thread pls take a look
Copy code
@Entity
@Table
data class User(
    @Column(unique = true, nullable = false)
    val username: String,
    @Column(unique = true, nullable = false)
    val email: String,
    val imageFileId: String,
    val firstName: String,
    val lastName: String,
    val active: Boolean = true,
    @JsonIgnore var password: String? = null,
    @Id @GeneratedValue(strategy = GenerationType.IDENTITY)
    val id: Long = -1,
    @Version var version: Int = 0,
    var createdAt: OffsetDateTime = OffsetDateTime.now(),
    var createdBy: String = "system",
    var modifiedAt: OffsetDateTime = OffsetDateTime.now(),
    var modifiedBy: String = "system"
) {
    @PrePersist
    fun prePersist() {
        createdAt = OffsetDateTime.now()
    }

    @PreUpdate
    fun preUpdate() {
        modifiedAt = OffsetDateTime.now()
    }

    fun deactivate() = copy(active = false).also { it.roles = this.roles }
    fun activate() = copy(active = true).also { it.roles = this.roles }


    @ManyToMany
    @JoinTable(
        name = "user_roles",
        joinColumns = [JoinColumn(name = "user_id")],
        inverseJoinColumns = [JoinColumn(name = "role_id")]
    )
    lateinit var roles: Set<Role>
}
It works good I think. I got problem related to my expectation about data classes - them can’t contain super class vals and vars in copy method(I wanted to create BaseDB object with common fields, but postpone this idea for now) and it can be tricky to use copy method. But still it isn’t problem of hibernate and other staff - like ManyToMany, PrePersist works fine
p.s. I`m using spring boot with spring data jpa.