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
764 stars 344 forks source link

Fetching an aggregate root-entity-set chain results in wrong data for the set #1802

Closed vpmuli closed 3 months ago

vpmuli commented 4 months ago

Check the attached example project. Run DemoApplicationTests to see the problem. I noticed this on Spring Data JDBC 3.2.5. Also applies to 3.3.0. 3.1.12 works as expected. It seems to me that the id of the root table is erroneously used for fetching the set. This is highly dangerous as wrong data is returned and if the returned aggregate is saved back to the database then the wrong set data is persisted.

bug.zip

vpmuli commented 4 months ago

Converting the Second record to a class with setters fixes the problem. Immutable class also has this bug.