In a One-To-Many relationship, how can I delete a child element without having to find and load up the parent, removing the element, update parent, THEN delete the child? To further illustrate my problem, I have the two classes Foo (parent) and Don (child of Don):
@Entity
public class Foo {
@Id
@GeneratedValue
private int id;
@OneToMany
private List<Don> dons;
public int getId() {
return id;
}
public List<Don> getDons() {
// (loads dons as because lazy loading)
return dons;
}
}
@Entity
public class Don {
@Id
@GeneratedValue
private int id;
public int getId() {
return id;
}
}
If I have a Don instance with several Foos referring to it, I would get the following exception:
Cannot delete or update a parent row: a foreign key constraint fails
I know I can remove the instance from Foo, but is there a way to remove Don instances without finding Foos? (as of performance)