以下に5つのドメインクラス(動的プログラミング)があります。私はレコードのチェックリストのヘッダーを2つのリストで更新する必要があります。これらのリストにも2つのリストがあり、合計5つのドメインがあります。 org.hibernate.exception.ConstraintViolationException:によって引き起こさorg.springframework.transaction.TransactionSystemException:JPAトランザクションをコミットできませんでした。javax.persistence.RollbackException
:私は、アップデート中に、私は次の例外を取得し、すべての5つのレコードを更新する必要がある親行を削除または更新できません:。外部キー制約が失敗した(
new1
checklist_property
、CONSTRAINTFK14E0B84E32ADD034
FOREIGN KEY(checklist_property_title
は)私は新しいレコードを置くために子レコードを削除)
checklist_property_title
(id
)を参照します。
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;
}
}
カスケード= CascadeType.DELETEあなたによって引き起こされ、このEROR子を削除しても、このエラーofffcourse親 –
で@OneToManyコレクションorphanRemoval = trueを追加しますが、それでも同じ問題 –
を示します子供の削除中に発生します。 –