I try to remove the parent, but I continue to violate the foreign key. If I put Cascade.ALL on the parent, it will also remove the children. And now this is what I want.
I have a parent class: Docteur
// bi-directional many-to-one association to Patient
@OneToMany (cascade = {CascadeType.PERSIST, CascadeType.MERGE, CascadeType.DETACH}, orphanRemoval = false, mappedBy = "docteur")
private List patients;
and my children: Patient
I suppose that
@ManyToOne ()
private Docteur docteur;
but in my case the patient has only one Doctor.
In my class Manager. I try a lot of things that don't work.
here is my latest version
Clinique clinique = read (clinique_ID);
Docteur docteur = entityManager.createNamedQuery("getDocteur", Docteur.class).setParameter("clinique_ID", clinique_ID).setParameter("docteur_ID", docteur_ID).getSingleResult();
clinique.getDocteurs().remove(docteur);
entityManager.merge(clinique);
entityManager.persist(clinique);
, :
: (jerabi_asteriskdb/Patient, CONSTRAINT FK340C82E5A10F077E (docteur_DOCTEUR_ID) Docteur (DOCTEUR_ID))