JPA, how to remove a parent without removing children?

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))

+3
2

, , docteur_id . . , , .

docteur, , docteur_id. , docteur_id null:

Docteur docteur = entityManager.createNamedQuery("getDocteur", Docteur.class).setParameter("clinique_ID", clinique_ID).setParameter("docteur_ID", docteur_ID).getSingleResult();

for (Patient patient : docteur.getPatients()) {
    patient.setDocteur(null);
}
docteur.patients.clear();
clinique.getDocteurs().remove(docteur);

, () Hibernate. . http://docs.jboss.org/hibernate/core/3.6/reference/en-US/html_single/#objectstate-overview.

+5

, . SQL 2003 5 :

  • CASCADE:
  • RESTRICT:
  • NO ACTION: , ,
  • SET NULL: null ( )
  • SET DEFAULT: ( , NULL)
0

All Articles