Aşağıda beş etki alanı sınıfı var (dinamik programlama). İçindeki iki liste ile kayıt kontrol listesi başlığını güncellemem gerekiyor, bu listeler sırayla iki listeye de sahip, yani toplam beş alan var. org.hibernate.exception.ConstraintViolationException: silebilir veya bir üst satır güncellenemiyor:org.springframework.transaction.TransactionSystemException: JPA işlemi yapılamadı, javax.persistence.RollbackException
Neden Olduğu: Ben güncelleme sırasında ben şu istisna olsun, tüm beş kayıtlarını güncellemeniz gerekir. Bir yabancı anahtar kısıtlaması başarısız (
new1
checklist_property
, KISITLAMAFK14E0B84E32ADD034
YABANCI KEY (checklist_property_title
) Ben yeni kayıtlar koymak için çocuk kayıtlarını silmek)
checklist_property_title
(id
) REFERANSLAR.
package com.stie.cmms.domain;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "checklist_header")
public class ChecklistHeader {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Long id;
@Column(name = "checklist_name")
String checklistName;
@Column(name = "remarks")
String prerequisite;
@ManyToOne(fetch = FetchType.EAGER)
@JoinColumn(name = "equipment")
Equipment1 equipment;
@JsonIgnore
@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(mappedBy = "checklistHeader", cascade = CascadeType.ALL)
List<ChecklistFaultDescription> faultDescription;
@JsonIgnore
@LazyCollection(LazyCollectionOption.TRUE)
@OneToMany(mappedBy = "checklistHeader", cascade = CascadeType.ALL)
List<ChecklistPropertyTitle> propertyTitles;
public List<ChecklistFaultDescription> getFaultDescription() {
return faultDescription;
}
public void setFaultDescription(List<ChecklistFaultDescription> faultDescription) {
this.faultDescription = faultDescription;
}
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public String getChecklistName() {
return checklistName;
}
public void setChecklistName(String checklistName) {
this.checklistName = checklistName;
}
public String getPrerequisite() {
return prerequisite;
}
public void setPrerequisite(String prerequisite) {
this.prerequisite = prerequisite;
}
public Equipment1 getEquipment() {
return equipment;
}
public void setEquipment(Equipment1 equipment) {
this.equipment = equipment;
}
public List<ChecklistPropertyTitle> getPropertyTitles() {
return propertyTitles;
}
public void setPropertyTitles(List<ChecklistPropertyTitle> propertyTitles) {
this.propertyTitles = propertyTitles;
}
}
//above is first domain class
package com.stie.cmms.domain;
import java.util.List;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "checklist_property_title")
public class ChecklistPropertyTitle {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Long id;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "checklist_header")
ChecklistHeader checklistHeader;
@Column(name = "title")
String title;
@JsonIgnore
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "checklistPropertyTitle", cascade = CascadeType.ALL)
List<ChecklistProperty> properties;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ChecklistHeader getChecklistHeader() {
return checklistHeader;
}
public void setChecklistHeader(ChecklistHeader checklistHeader) {
this.checklistHeader = checklistHeader;
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public List<ChecklistProperty> getProperties() {
return properties;
}
public void setProperties(List<ChecklistProperty> properties) {
this.properties = properties;
}
}
//my third domain class
// there are five domain class
package com.stie.cmms.domain;
import java.util.List;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;
import com.fasterxml.jackson.annotation.JsonIgnore;
@Entity
@Table(name = "checklist_fault_description")
public class ChecklistFaultDescription {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "id")
Long id;
@ManyToOne(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
@JoinColumn(name = "checklist_header")
ChecklistHeader checklistHeader;
@Column(name = "title1")
String title1;
@JsonIgnore
@LazyCollection(LazyCollectionOption.FALSE)
@OneToMany(mappedBy = "checklistFaultTitle", cascade = CascadeType.ALL)
List<ChecklistFaults> faults;
public Long getId() {
return id;
}
public void setId(Long id) {
this.id = id;
}
public ChecklistHeader getChecklistHeader() {
return checklistHeader;
}
public void setChecklistHeader(ChecklistHeader checklistHeader) {
this.checklistHeader = checklistHeader;
}
public String getTitle1() {
return title1;
}
public void setTitle1(String title1) {
this.title1 = title1;
}
public List<ChecklistFaults> getFaults() {
return faults;
}
public void setFaults(List<ChecklistFaults> faults) {
this.faults = faults;
}
}
çağlayan = CascadeType.DELETE sizin neden bu eror çocuğu silmek ama bu hatanın offfcourse ebeveyni –
yılında @ OneToMany toplama orphanRemoval = true ekleyin ama yine aynı sorun –
gösteren çocuğun silinmesi sırasında ortaya çıkar. –