hibernate insert to a collection causes a delete then all the items in the collection to be inserted again

后端 未结 7 1668
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-17 21:09

I have a many to may relationship CohortGroup and Employee. Any time I insert an Employee into the CohortGroup hibernate deletes the group from the resolution table and ins

7条回答
  •  伪装坚强ぢ
    2020-12-17 21:49

    I have same issue. I changed from List to Set. It work for me.

    @ManyToMany(cascade = { PERSIST, MERGE, REFRESH })
    @JoinTable(name="MYSITE_RES_COHORT_GROUP_STAFF",
    joinColumns={@JoinColumn(name="COHORT_GROUPID")},
    inverseJoinColumns={@JoinColumn(name="USERID")})
    public Set getMembers(){
      return members;
    }
    
    @ManyToMany(mappedBy="members",cascade = { PERSIST, MERGE, REFRESH } )
    public Set getMemberGroups(){
      return memberGroups;
    }
    

提交回复
热议问题