Hibernate: Removing item from a List does not persist

前端 未结 4 1467
旧时难觅i
旧时难觅i 2020-12-06 09:59

I am having trouble when removing an item from a list. The list is defined in a superclass, but the Hibernate annotations are applied to property accessors in a subclass. Th

4条回答
  •  孤街浪徒
    2020-12-06 10:57

    You have to explicitly specify cascade as CascadeType.DELETE_ORPHAN.

    Try to change code to

    @OneToMany    
    @Cascade(cascade = {CascadeType.ALL, CascadeType.DELETE_ORPHAN}, mappedBy = "temporal")
    

    Part from hibernate docs:

    If the child object's lifespan is bounded by the lifespan of the parent object, make the parent a full lifecycle object by specifying CascadeType.ALL and org.hibernate.annotations.CascadeType.DELETE_ORPHAN (please refer to the Hibernate reference guide for the semantics of orphan delete)

提交回复
热议问题