Repository navigation
Fix: Delete of deeply nested entities compares ids with root instead of parent - #2418
sharanggupta wants to merge 1 commit into
Conversation
The delete queries derived by Spring Data JDBC deleted the entities of every nested path with the ids of the deleted aggregate roots. The back reference of an entity nested in another entity with an id holds the id of that other entity, though, so the nested entities of another aggregate got deleted when their parent had the same id as one of the deleted roots. These entities are already deleted by the recursion for the entity holding the id, which selects those ids from the deleted roots. Skip them in the loop over the paths of the root. Signed-off-by: Sharang Gupta <sharang@sharanggupta.dev>
|
@schauder, while looking at #2123 I found that the per-entity recursion in Rather than patching the recursion three times, I have a branch that builds the nested deletes in one pass over the aggregate's paths, deepest first, where each delete's condition navigates to the root through a sub-select on the table of every ancestor with an id, the way main...sharanggupta:spring-data-relational:derived-delete-subselects It carries the regression tests in If you prefer that direction I can switch this PR to it, which would close #2123 as well; otherwise this PR stays the minimal fix for #2417 and I can offer the id-column fix separately on #2123. |
Closes #2417
JdbcDeleteQueryCreator.deleteRelationsnow skips the paths of entities nested in another entity with an id. The recursion for that entity already deletes them, through the right ids.The new test in
JdbcRepositoryWithCollectionsChainHsqlIntegrationTestsfails without the change: a child of the other aggregate loses its grandchildren. The spring-data-relational and spring-data-jdbc unit tests and the HSQL integration tests pass.