我一直在这里查看有关此异常的信息,但找不到解决方案,因此我认为只是粘贴我的代码,以防万一出问题。
当我尝试找到EvaluationSelectionCriteria实体时,我正在接收此异常。
Exception: org.hibernate.HibernateException: A collection with cascade="all-delete- orphan" was no longer referenced by the owning entity instance: com.greenvalley.etendering.domain.Candidacy.evaluationSelectionCriterias
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY)
@JoinColumn(name = "candidacy_id", nullable = false)
@XmlElement
@JsonIgnore
@Getter
@Setter
private List<EvaluationSelectionCriteria> evaluationSelectionCriterias = new ArrayList<>();
@ManyToOne
@JoinColumn(name = "candidacy_id", nullable = false, insertable = false, updatable = false)
@XmlTransient
@Getter
@Setter
private Candidacy candidacy;
最佳答案
我已经通过将setXX方法替换为这样来解决了这个问题
public void setEvaluationSelectionCriterias(List<EvaluationSelectionCriteria> evaluationSelectionCriterias) {
if(this.evaluationSelectionCriterias == null) { //if not already initialized
this.evaluationSelectionCriterias = evaluationSelectionCriterias;
} else {
this.evaluationSelectionCriterias.clear();
this.evaluationSelectionCriterias.addAll(evaluationSelectionCriterias);
}