问题描述
我正在尝试将 Spring Data JDBC 与 Kotlin 数据类一起使用,在将 @Transient
属性添加到主构造函数后,我在简单的 findById
调用中收到错误:
java.lang.IllegalStateException: required property transient not found for class mitasov.test_spring_data_with_kotlin.Entity!
我的实体类如下所示:
data class Entity(
@Id
var id: String,var entityName: String,@Transient
var transient: List<TransientEntity>? = mutablelistof(),)
阅读 that issue 后,我尝试制作没有 @PersistenseConstructor
字段的 @Transient
:
data class Entity(
@Id
var id: String,) {
@PersistenceConstructor
constructor(
id: String,entityName: String,) : this(id,entityName,mutablelistof())
}
但这对我没有帮助,我仍然遇到那个错误。
我该如何解决这个问题?
解决方法
事实证明,我的第二次尝试是解决方案。
诀窍在于我的测试运行/调试配置。
在 IDEA Preferences 中,我选中了 Preferences | Build,Execution,Deployment | Build Tools | Maven | Runner — Delegate IDE build/run actions to Maven
复选框,这意味着我需要在运行测试之前手动重新编译我的项目。
解决方案
就是这样,错误的解决方法
java.lang.IllegalStateException: Required property transient not found for class mitasov.test_spring_data_with_kotlin.Entity!
正在制作没有 @PersistenseConstructor
字段的 @Transient
:
data class Entity(
@Id
var id: String,var entityName: String,@Transient
var transient: List<TransientEntity>? = mutableListOf(),) {
@PersistenceConstructor
constructor(
id: String,entityName: String,) : this(id,entityName,mutableListOf())
}