Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PATCH request for updating nested collections does not work correctly when there is deleted items [DATAREST-1533] #1889

spring-projects-issues opened this issue Jun 21, 2020 · 0 comments


Copy link

@spring-projects-issues spring-projects-issues commented Jun 21, 2020

Rasha Elsayed opened DATAREST-1533 and commented

I have a scenario where a parent entity "parent" has a collection of "child" entities (OneToMany-relation with CASCADE = all). The repository of the child entity is not exported. I have to update the "parent" and "children" in the same call (same transaction). So i am confronted with the following scenario

P1: name = parent1

ch1: id=1, name = child1

ch2: id=2, name = child2

ch3: id=3, name = child3


Now delete +child2+ and add new child name = +child4.+ and Send a PATCH request to persist. This results in the following:

ch1: id=1, name = child1

ch2: id=2, name = child4

ch3: id=3, name = child3

So the new child (child4) took the same id as the deleted one (child2).

If there is any foreign keys on the child entity, this will lead to wrong references. 


I found that inside the class DomainObjectReader, method handleArrayNode, that both collections, the one from the payload (array) and the one from the DB (collection) are read and iterated on to merge the items. In case of deletion, items will not be at the same index. Therfore it is not guranteed that an item is merged with its correct counterpart. Would it be an idea to merge two elements if their ids match? Just any mechanism making sure that the correct pair is merged.


I think the problem was mentioned under the issue (see last comment)

Affects: 3.3.1 (Neumann SR1)

1 votes, 1 watchers

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet

No branches or pull requests

2 participants