Skip to content

Mapping failure with Composite Key and Inherited Audit Fields - Kotlin #2188

@Aadammm

Description

@Aadammm

When an entity uses both:

  • A composite primary key
  • Inherited fields from a base class

Then read operations (findById(), findAll()) fail during column mapping with:
IllegalArgumentException: Cannot obtain ColumnInfo for embedded path

Both features work independently.
INSERT operations via a custom InsertRepository seem to work correctly, but read operations consistently fail during the mapping phase.

Stack Trace:

Cannot obtain ColumnInfo for embedded path
java.lang.IllegalArgumentException: Cannot obtain ColumnInfo for embedded path
	at org.springframework.util.Assert.isTrue(Assert.java:136)
	at org.springframework.data.relational.core.mapping.AggregatePath$ColumnInfo.of(AggregatePath.java:502)
	at org.springframework.data.relational.core.mapping.DefaultAggregatePath.lambda$new$1(DefaultAggregatePath.java:47)
	at org.springframework.data.util.Lazy.getNullable(Lazy.java:136)
	at org.springframework.data.util.Lazy.get(Lazy.java:114)
	at org.springframework.data.relational.core.mapping.DefaultAggregatePath.getColumnInfo(DefaultAggregatePath.java:326)
	at org.springframework.data.relational.core.conversion.MappingRelationalConverter$DocumentValueProvider.getValue(MappingRelationalConverter.java:1229)
	at org.springframework.data.jdbc.core.convert.MappingJdbcConverter$ResolvingRelationalPropertyValueProvider.lambda$new$0(MappingJdbcConverter.java:409)  

Code:

@Table("Test")
data class Test(
    @Id
    var id: TestId,

    @field:Column("Value")
    var value: Double? = null,
) : Ancestor()

data class TestId(
    @field:Column("Key_first")
    var keyFirst: String,

    @field:Column("Key_second") 
    var keySecond: String,
) : Serializable

open class Ancestor (
    @field:Column("CREATED_AT")
    var createdAt: Instant? = null,

    @field:Column("CREATED_BY")
    var createdBy: String? = null
) : Serializable

Alternative configuration that does work, but inheritance is required in our domain model:

@Embedded.Nullable 
var ancestor: Ancestor = Ancestor()

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions