如何在Kotlin中初始化注释的数组属性

@Entity @Table(name = "t_payment") data class PaymentEntity( @ManyToOne(cascade = CascadeType.DETACH) @JoinColumn(name = "user_id", nullable = false) var user: User? = null) : Serializable { } 

作为编译错误的结果: "Type mismatch"

cascade注释属性接受一个CascadeType数组,因此您需要将您的@ManyToOne用法更改为:

 @ManyToOne(cascade = arrayOf(javax.persistence.CascadeType.DETACH))