spring-projects / spring-data-relational

Spring Data Relational. Home of Spring Data JDBC and Spring Data R2DBC.
https://spring.io/projects/spring-data-jdbc
Apache License 2.0
740 stars 342 forks source link

Incorrect mapping for @Embedded entities with @Id queried via NamedParameterJdbcTemplate #1736

Closed jmrandol closed 2 months ago

jmrandol commented 5 months ago

I ran into an issue where I'm querying entities using NamedParameterJdbcTemplate and the mapping logic gets confused. See attached code example.

In 3.1.x, the tests pass. Everything is mapped correctly when querying for PersonPlace entities, but when I attempted an upgrade to 3.2.2, the mapping logic looks to have changed significantly (BasicJdbcConverterto MappingJdbcConverter) and is now trying to incorrectly map the ID fields. Whether this is a bug or I'm doing this way wrong and 3.2.x is revealing that would be nice to know.

test-database.zip

jmrandol commented 3 months ago

Tried to delve into this a little bit. I can't pinpoint exactly where it seems to be going wrong, but at some point the embedded prefix is dropped or ignored when attempting to get the embedded id property from the RowDocument.

jmrandol commented 3 months ago

The failure happens here: https://github.com/spring-projects/spring-data-relational/blob/main/spring-data-jdbc/src/main/java/org/springframework/data/jdbc/core/convert/MappingJdbcConverter.java#L343 because the idProperty does not contain the embedded prefix.

jmrandol commented 2 months ago

This appears to be working again in 3.3.0!