A collection with cascade=“all-delete-orphan” was no longer referenced by the owning entity instance

后端 未结 5 1223
终归单人心
终归单人心 2021-02-01 07:26

In my application, a hibernate operation goes like this. The application updates a parent entity with new values from the request and deletes all the existing (previously insert

5条回答
  •  梦谈多话
    2021-02-01 08:22

    I faced the same issue and get it solved as follows:

    1- add {CascadeType.ALL}, orphanRemoval=true in all @OneToMany annotations in all entity Childs of that element.

    2- Check the hashcode() and equalls() of those entities, some times they have erros

    3- Don't use parent.setChilds(newChilds); as the engine will ask for missing the reference to the childs, but use instead use

    parent.getChilds().clear();
    parent.getChilds().add(Child);
    

    or

    parent.getChilds().addAll(Childs);
    

    Those steps solved my issue after 4 Hours of research

提交回复
热议问题