JPA / Hibernate Cascade.Remove use case for @ManyToOne

后端 未结 1 1780
面向向阳花
面向向阳花 2021-01-14 07:13

With the following:

//User class...

@ManyToOne(cascade=CascadeType.REMOVE)
@JoinColumn(name=\"INSTITUTION_ID\")
public void setInstitution(final Institution         


        
相关标签:
1条回答
  • 2021-01-14 07:41

    You are right, it is rarely (if ever) needed and not portable construct to use CascadeType.REMOVE with ManyToMany or ManyToOne . This is documented as follows in JPA 2.0 specification:

    The relationship modeling annotation constrains the use of the cascade=REMOVE specification. The cascade=REMOVE specification should only be applied to associations that are specified as OneToOne or OneToMany. Applications that apply cascade=REMOVE to other associations are not portable.

    Reason why it exists is likely just that there was no reasonable way to limit allowed values of cascade to some subset of CascadeType enumeration's values.

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