У меня есть rellationship между 2 класса документа и МедсанJPA OneToOne каскадное удаление
@Entity
public class Document implements Serializable {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private long id;
private String annee;
private Date dateVisite;
private String secteur;
private String typeVisite;
@OneToOne(fetch=FetchType.LAZY,cascade=CascadeType.REMOVE)
@JoinColumn(name = "idMedecin")
private Medecin medecin;
public Document(String annee,
Date dateVisite, String secteur, String typeVisite) {
super();
this.annee = annee;
this.dateVisite = dateVisite;
this.secteur = secteur;
this.typeVisite = typeVisite;
}
public String getSecteur() {
return secteur;
}
public void setSecteur(String secteur) {
this.secteur = secteur;
}
public String getTypeVisite() {
return typeVisite;
}
public void setTypeVisite(String typeVisite) {
this.typeVisite = typeVisite;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getAnnee() {
return annee;
}
public void setAnnee(String annee) {
this.annee = annee;
}
public Date getDateVisite() {
return dateVisite;
}
public void setDateVisite(Date dateVisite) {
this.dateVisite = dateVisite;
}
}
и Медсан сущности является
@Entity
public class Medecin implements Serializable {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private long id;
private String nom;
private String secteur;
private int telephone;
private int specialite;
public Medecin() {
super();
// TODO Auto-generated constructor stub
}
public Medecin(String nom, String secteur, int telephone, int specialite) {
super();
this.nom = nom;
this.secteur = secteur;
this.telephone = telephone;
this.specialite = specialite;
}
public long getId() {
return id;
}
public void setId(long id) {
this.id = id;
}
public String getNom() {
return nom;
}
public void setNom(String nom) {
this.nom = nom;
}
public String getSecteur() {
return secteur;
}
public void setSecteur(String secteur) {
this.secteur = secteur;
}
public int getTelephone() {
return telephone;
}
public void setTelephone(int telephone) {
this.telephone = telephone;
}
public int getSpecialite() {
return specialite;
}
public void setSpecialite(int specialite) {
this.specialite = specialite;
}
}
проблема заключается в том, что после того, как я генерировать базы данных я хочу, если я удалить запись документа из базы данных, я хочу, чтобы запись medecin также была удалена, но в моем случае, если я удалю запись документа, запись медика не удаляется
это не решает проблему, скажи мне, есть ошибка: Не удается удалить или обновить parent row: ограничение внешнего ключа завершается с ошибкой (db_bri_sante.medecin, внешний ключ (document_id) reference document (id)) – user3578199
Можете ли вы показать мне свой код для удаления документа? Я обновил, как я это делаю, и он отлично работает. –