Uploaded image for project: 'Spring Data REST'
  1. Spring Data REST
  2. DATAREST-1533

PATCH request for updating nested collections does not work correctly when there is deleted items



    • Type: Bug
    • Status: Open
    • Priority: Major
    • Resolution: Unresolved
    • Affects Version/s: 3.3.1 (Neumann SR1)
    • Fix Version/s: None
    • Component/s: Repositories
    • Labels:


      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 https://jira.spring.io/browse/DATAREST-1012 (see last comment)




            olivergierke Oliver Drotbohm
            relsayed8205 Rasha Elsayed
            Last updater:
            Spring Issues Spring Issues
            1 Vote for this issue
            1 Start watching this issue