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

后端 未结 5 1271
终归单人心
终归单人心 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条回答
  •  萌比男神i
    2021-02-01 08:15

    It worked for me.

    1. Cleared all my child entities.
    2. Instead of setting the new child entities to my parent object, I have used addAll method to add the new child entities.

      parent.getChildren().clear();
      parent.getChildren().addAll(newChildrenList);
      
      @OneToMany(mappedBy = "parent", fetch = FetchType.LAZY, 
                 cascade = CascadeType.ALL, orphanRemoval = true)  
      
      public Set getChildren() {
          return this.children;
      }
      

提交回复
热议问题