Right now, if I want to delete a Parent entry from database, I would use cascade annotation in the Parent class, so that a deletion of Parent would also delete any children tied to it. Like this:
@Entity
public class Parent implements Serializable {
@Id
@GeneratedValue
private long id;
@OneToMany(mappedBy = "parent", cascade = CascadeType.REMOVE)
private Set<Child> children;
}
@Entity
public class Child implements Serializable {
@Id
@GeneratedValue
private long id;
@ManyToOne
@JoinColumn
private Parent parent;
}
The actual deletion would be like this:
this.parentRepository.delete(parentID);
However, if I want to explicitly choose whether to cascade delete or to simple delete, how would I do that?
I don't think I can choose to turn off the cascade annotation in code manually, so is there a way to cascade delete without using annotation?