//Parent class
Class parent
{
String id;
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent1", cascade = CascadeType.ALL)
private Set<child> groupMembers = new HashSet<>(0);
@OneToMany(fetch = FetchType.LAZY, mappedBy = "parent2", cascade = CascadeType.ALL)
private Set<child> groupMembers1 = new HashSet<>(0);
}
//clild class
class child
{
String id;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent1")
private parent parent1;
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "parent2")
private parent parent2;
}
//While deleting one of the parent object in sprint boot using
parentRepository.delete(id); it still says ERROR: update or delete on table "parent" violates foreign key constraint "child_parent2_fkey" on table "child"
Tried deleting with separate deletion queries individually on child class and it worked.
using cascade its not working
New contributor
koduri vikas is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.