I want to delete the parent if the child gets deleted while the parent doesn’t have any other children.
If i use CascadeType.ALL i get a foreign key error when attempting to delete a child while more than one child exists.
@Entity
public class Child {
@Id
@GeneratedValue
private long id;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private Parent parent;
}
@Entity
public class Parent {
@Id
@GeneratedValue
private long id;
}
If i try to delete a child i will get an error because it attempts to delete a parent which still has other children pointing to it.
New contributor
sfdgioj111 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.