Spring Data JDBC-Kotlin支持-找不到类的必需属性



我正试图将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(),
)

在阅读了这个问题之后,我尝试在没有@Transient字段的情况下制作@PersistenseConstructor

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())
}

但这对我没有帮助,我仍然会犯这个错误。

我该如何解决这个问题?

事实证明,我的第二次尝试就是解决方案。

诀窍就在我的测试运行/调试配置中。

在IDEA首选项中,我选中了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!

正在制作没有@Transient字段的@PersistenseConstructor

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())
}

最新更新