2

I'm trying to use Spring Data JDBC with Kotlin data-classes, and after adding @Transient property to primary constructor I received error on simple findById call:

java.lang.IllegalStateException: Required property transient not found for class mitasov.test_spring_data_with_kotlin.Entity!

my entity class looks like below:

data class Entity(
    @Id
    var id: String,
    var entityName: String,
    @Transient
    var transient: List<TransientEntity>? = mutableListOf(),
)

After reading that issue I've tried to make @PersistenseConstructor without @Transient field:

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

But this didn't help me and I'm still getting that error.

How can I solve this problem?

RomanMitasov
  • 925
  • 9
  • 25
  • I personally recommend using Java instead of Kotlin's data class for JPA. – Pemassi Jan 01 '21 at 18:43
  • This is not JPA, this is JDBC, please be more attentive. Spring Data JDBC supports Kotlin nicely, see [official docs](https://docs.spring.io/spring-data/jdbc/docs/2.1.2/reference/html/#mapping.kotlin) – RomanMitasov Jan 01 '21 at 18:48

1 Answers1

5

It's turned out that my second attempt IS the solution.

The trick was in my Run/Debug configuration for tests.

In IDEA Preferences I have checked Preferences | Build, Execution, Deployment | Build Tools | Maven | Runner — Delegate IDE build/run actions to Maven checkbox, and this means that I need to manually recompile my project before running tests.

Solution

So, this is it, the solution for error

java.lang.IllegalStateException: Required property transient not found for class mitasov.test_spring_data_with_kotlin.Entity!

is making @PersistenseConstructor without @Transient fields:

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())
}
RomanMitasov
  • 925
  • 9
  • 25