Cannot obtain ColumnInfo for embedded path
spring-data-jdbc 4.0.0 A composite primary key exception
@Data
@Table("tenant_user")
public class TenantUser {
@Id
private TenantUserID id;
private String alias;
}
public record TenantUserID(String uid, String tid) {
}
Then run:
tenantUserRepository.findById(new TenantUserID("1", "2"))
Stack Trace:
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)
at org.springframework.data.jdbc.core.convert.MappingJdbcConverter$ResolvingRelationalPropertyValueProvider.potentiallyAppendIdentifier(MappingJdbcConverter.java:422)
at org.springframework.data.jdbc.core.convert.MappingJdbcConverter$ResolvingRelationalPropertyValueProvider.<init>(MappingJdbcConverter.java:408)
at org.springframework.data.jdbc.core.convert.MappingJdbcConverter.newValueProvider(MappingJdbcConverter.java:364)
at org.springframework.data.relational.core.conversion.MappingRelationalConverter.populateProperties(MappingRelationalConverter.java:548)
When change class 'TenantUser' to reocrd type
@Table("tenant_user")
public record TenantUser(
@Id TenantUserID id,
String alias) {
}
The method 'findById' is work!
I tried to reproduce the issue in https://github.com/schauder/jdbc-2201 but failed.
Please provide a Minimimal Reproducable Example, preferable as a PR to the Github repository mentioned above. Alternatively feel free to provide your own repo or send a zip file. Make sure to include the database, either as an in memory database or if that is not possible using Testcontainers.
Found a workaround for this bug. You can create a full constructor annotated with @PersistenceCreator, then it works with a plain class.
I tried to reproduce the issue in https://github.com/schauder/jdbc-2201 but failed.
It works because the table is empty. If you save a queried entity before, it will fail with a ColumnInfo exception.
@DerekHQ @schauder @vitos23
Hi everyone, thanks for reporting this.
I’ve looked into the issue and have been able to identify the root cause related to how DocumentValueProvider handles embedded paths for composite IDs. It seems the current implementation calls getColumnInfo() without checking for embedded paths, which leads to an exception.
I intend to work on a fix by adjusting DocumentValueProvider to properly handle embedded paths (e.g., checking path.isEmbedded() and recursively processing embedded properties as needed).
Please let me know if anyone else is already working on this. If not, I’ll proceed with a PR and keep this thread updated with progress.
Thanks!