JPA / Hibernate Cascade. Use use case for @ManyToOne

With the following:

//User class...

@ManyToOne(cascade=CascadeType.REMOVE)
@JoinColumn(name="INSTITUTION_ID")
public void setInstitution(final Institution institution) {
    this.institution = institution;
}

Does this mean that deleting the User object will delete the associated Institution object? If so, I do not understand why this is necessary. Say, for example, that an institution had many users. Does this mean that deleting one of these users removes the institution, in which case all other users also lose it?

+3
source share
1 answer

You are right, rarely (if ever) is required, and not a portable construct for using CascadeType.REMOVE with ManyToMany or ManyToOne. This is described in the JPA 2.0 specification:

cascade = REMOVE. cascade = REMOVE , OneToOne . , cascade = REMOVE .

, , , , CascadeType.

+4

All Articles