0

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

示例代码:

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'

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

4

1 回答 1

2
interface Foo {
    @get:javax.persistence.Transient
    val doodah: Boolean
        get() = /* some default implementation */
}
于 2019-11-24T16:27:27.177 回答