deleted object would be re-saved by cascade (remove deleted object from associations)

后端 未结 18 1194
轮回少年
轮回少年 2020-11-30 00:19

i have the following two entities:

1- PlayList:

@OneToMany(fetch = FetchType.EAGER, mappedBy = \"playlist\", orphanRemoval = true, c         


        
18条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 00:50

    I had the same exception, caused when attempting to remove the kid from the person (Person - OneToMany - Kid). On Person side annotation:

    @OneToMany(fetch = FetchType.EAGER, orphanRemoval = true, ... cascade    = CascadeType.ALL)
    public Set getKids() {    return kids; }
    

    On Kid side annotation:

    @ManyToOne(cascade = CascadeType.ALL)
    @JoinColumn(name = "person_id")
    public Person getPerson() {        return person;    }
    

    So solution was to remove cascade = CascadeType.ALL, just simple: @ManyToOne on the Kid class and it started to work as expected.

提交回复
热议问题