1

I'm moving to Micronaut Data JDBC and Kotlin from Spring Data JDBC and Java, and have trouble with @Transient on a Kotlin property which does not have a backing field.

Example code:

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> {
}

At runtime I get a complaint from Postgres:

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

Hmmm, looks like Micronaut Data wants to serialize/deserialize the inherited property. So I tried @Transient on the property, and compilation fails with:

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

Suggestions on how to solve this?

binkley
  • 573
  • 1
  • 6
  • 8

1 Answers1

3
interface Foo {
    @get:javax.persistence.Transient
    val doodah: Boolean
        get() = /* some default implementation */
}
Nikolai Shevchenko
  • 7,083
  • 8
  • 33
  • 42
  • This also produces a compilation error: ``` This annotation is not applicable to target 'member property without backing field or delegate' and use site target '@get' ``` – binkley Nov 24 '19 at 19:12
  • 1
    @binkley are you sure that you are using proper annotation class (javax.persistence.Transient)? – Nikolai Shevchenko Nov 24 '19 at 19:38
  • you are perfectly correct. I had pulled in the Kotlin JVM annotation, not the persistence one. Your answer is spot on, thank you! – binkley Nov 24 '19 at 19:49