I am not able to delete child entities when OneToMany relationship is with the same entity. Cascade is not working. If OneToMany relationship is between 2 different entities then cascade works fine. How to enforce cascade.delete when the relationship is between same entities. Cascade works fine during save.
@Entity
@Data
public class QuestionBank implements Serializable{
private static final long serialVersionUID = 1L;
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long questionBankId;
private String questionSeriesId;
private String questionShortText;
@OneToMany(mappedBy="parentQuestionBank", cascade = CascadeType.ALL, orphanRemoval = true)
private List<QuestionBank> childQuestionBankList;
@ManyToOne()
private QuestionBank parentQuestionBank;
}
@DeleteMapping("/getQB/{id}")
public void deleteQB(@PathVariable Long id) {
QuestionBank qb = queBankRepo.findById(id).get();
queBankRepo.delete(qb);
}