【发布时间】:2016-01-11 11:00:33
【问题描述】:
class Attribute{
--- other entity def
@OneToMany(fetch=FetchType.LAZY, orphanRemoval=true, cascade=CascadeType.ALL)
@JoinColumn(name="ATTRDEFID", nullable=false, insertable=false , updatable=false)
@OrderBy("IDX")
private List<Constraint> constraints = new ArrayList<Constraint>();
--- other entity def
}
在更新/保存属性时,约束为空。此错误仅在更新的情况下引发。
org.springframework.orm.jpa.JpaSystemException:拥有的实体实例不再引用具有 cascade="all-delete-orphan" 的集合:com.revitas.cm.persistence.term.Attribute.constraints;嵌套异常是 org.hibernate.HibernateException:拥有的实体实例不再引用具有 cascade="all-delete-orphan" 的集合:com.revitas.cm.persistence.term.Attribute.constraints
当我设置空集合而不是null时,它保存成功。
if(attribute.getConstraints()==null){
attribute.setConstraints(new ArrayList<>());
}
为什么会抛出这样的错误?为什么通过空集合解决?它是否正确解决方案? 我在谷歌上搜索与this 相关的内容。但不明白为什么会出现这样的问题。
【问题讨论】:
-
怎么变成
null?你可能没有正确合并它。 -
是的
.merge()上不应为空。它打开了休眠问题。我回答了它,这可能对其他人有帮助。此值设置为 json 的一部分。它可以通过设置 [] 或如果为 null 则不传递元素来解决。