spring-data-relational icon indicating copy to clipboard operation
spring-data-relational copied to clipboard

Mapping failure with Composite Key and Inherited Audit Fields - Kotlin

Open Aadammm opened this issue 1 month ago • 1 comments

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

Aadammm avatar Dec 01 '25 05:12 Aadammm

I’ve opened PR #2193 to address this issue.

The change makes StringBasedJdbcQuery preserve JDBCType.OTHER when binding parameters, and adds a regression test using a custom converter that returns JdbcValue.of(..., JDBCType.OTHER) to verify the behavior.

Feedback is very welcome.

parazit-IR avatar Dec 06 '25 12:12 parazit-IR