如何将@Transient与缺少支持字段的Micronaut Data和Kotlin属性一起使用?



我正在从Spring Data JDBC和Java迁移到Micronaut Data JDBC和Kotlin,并且在没有支持字段的Kotlin属性上@Transient时遇到问题。

示例代码:

interface Foo {
// @JvmDefault here had no effect on my problem
// @Transient does not compile here
val doodah: Boolean
get() = /* some default implementation */
}
// Bar implements Foo for reasons unrelated to this question, part of an internal "microframework"
@Entity
@Introspected
@Table(name = "bar")
data class Bar(@Id var id: Long /* , more properties */) : Foo {
}
@JdbcRepository(dialect = POSTGRES)
interface BarRepository : CrudRepository<Bar, Long> {
}

运行时,我收到Postgres的投诉:

org.postgresql.util.PSQLException: ERROR: column child_record_.doodah does not exist

嗯,看起来Micronaut Data想要序列化/反序列化继承的属性。 所以我尝试@Transient属性,编译失败,并显示:

This annotation is not applicable to target 'member property without backing field or delegate'

关于如何解决这个问题的建议?

interface Foo {
@get:javax.persistence.Transient
val doodah: Boolean
get() = /* some default implementation */
}

最新更新