JPA OneToMany : List vs Set

后端 未结 2 1406
有刺的猬
有刺的猬 2021-01-31 10:19

I have two entities: UserAccount and Notification. These have a relationship as shown below.

 public class UserAccount {

    @Id
    @         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2021-01-31 10:44

    List: Allows duplicate elements in it.

    Set: All elements should be unique.

    Now, delete may be happening because you are over-writing element in list, and so when you modify persisted entity of UserAccount type, it is removing the entity which is in list previously.

提交回复
热议问题