11/13/2018, 8:37 AM
It means the
should be
and nullable type? I should every time write
val id =!!
in this case. I hope JBoss team will do improvement for Kotlin in the future (for Hibernate).


11/13/2018, 9:24 AM
hi there probably this message is good to start thread pls take a look
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 =,
    var createdBy: String = "system",
    var modifiedAt: OffsetDateTime =,
    var modifiedBy: String = "system"
) {
    fun prePersist() {
        createdAt =

    fun preUpdate() {
        modifiedAt =

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

        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.