RomanMitasov
RomanMitasov

Reputation: 1021

Spring Data JDBC - Kotlin support - Required property not found for class

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?

Upvotes: 2

Views: 2568

Answers (1)

RomanMitasov
RomanMitasov

Reputation: 1021

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

Upvotes: 6

Related Questions