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

后端 未结 7 1681
爱一瞬间的悲伤
爱一瞬间的悲伤 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:56

    You have to define hashCode() and equals() on your CohortGroup and Employee entities. This can be done automatically by your IDE and it can either be on the primary key (sometimes not a good idea) or on a business key (preferable).

    Read this article.

提交回复
热议问题