I have inherited a code base on which nearly all relations have the following annotations:
@OneToMany(fetch = FetchType.LAZY, cascade = { CascadeType.REMOVE
Let's say you have a one-to-one directional relationship
class House {
@OneToOne
Object door;
}
If you use CascadeType.REMOVE then deleting the house will also delete the door.
@OneToOne(cascade=CascadeType.REMOVE)
Object door;
If you use @OnDelete then deleting the door will also delete the house.
@OneToOne
@OnDelete(action = OnDeleteAction.CASCADE)
Object door;
Read more here: http://www.ninthavenue.com.au/jpa-cascadetype-remove-vs-hibernate-ondelete