Removing child from collection using JPA

前端 未结 1 663
名媛妹妹
名媛妹妹 2021-02-05 05:52

I\'m using JPA over Hibernate in my web-app. Here are two entities (only getters are shown):

class Child {
  private Parent parent;

  @ManyToOne(optional=false)         


        
相关标签:
1条回答
  • 2021-02-05 06:31

    For JPA 2.0 you can set orphanRemoval=true of the @OneToMany

    For JPA 1.0, you should use hibernate-specific annotations. That is the @Cascade annotation (instead of the cascade attribute), with a value of

    @Cascade({CascadeType.ALL, CascadeType.DELETE_ORPHAN})
    

    Hibernate 3.5+ implement JPA 2.0

    0 讨论(0)
提交回复
热议问题