listPolicyDocumentDOList

listPolicyDocumentDOList

This question already has answers here:
Hibernate - A collection with cascade=”all-delete-orphan” was no longer referenced by the owning entity instance

(23个答案)


去年关闭。




我有PolicyDO和PolicyDocumentDO。它们之间的关系如下
PolicyDO.hbm.xml

<bag name="listPolicyDocumentDOList" cascade="all-delete-orphan" lazy="false"   inverse="true">
            <key column="POLICYSEQ" />
            <one-to-many class="dataobjects.policy.PolicyDocumentDO" />
PolicyDO.java
protected List<PolicyDocumentDO> policyDocumentDOList = new ArrayList<PolicyDocumentDO>();
 public java.util.List<PolicyDocumentDO> getListPolicyDocumentDOList() {
    return this.policyDocumentDOList;
  }

  public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
      policyDocumentDOList.clear();
      policyDocumentDOList = list;
  }


    PolicyDocumentDO.hbm.xml

    <many-to-one name="parentGuidObj" class="dataobjects.policy.PolicyDO"  not-null="true" >
            <column name="POLICYSEQ"  />
    </many-to-one>

每当我尝试从数据库中查询以下内容时
session = sessionFactory.openSession();
Query query = session.createQuery(strBuff.toString());
List listQuery = query.list();

我收到以下错误
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:

dataobjects.policy.PolicyDO.listPolicyDocumentDOList

所以在谷歌搜索之后,我在PolicyDO中设置listPolicyDocumentDOList时做了以下更改
public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
      policyDocumentDOList.clear();
      policyDocumentDOList = list;
  }

然后我也遇到了错误。
我还能做些什么来解决此错误。
谢谢

最佳答案

更改

public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
    policyDocumentDOList.clear();
    policyDocumentDOList = list;
}


public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
    policyDocumentDOList.clear();
    policyDocumentDOList.addAll(list);
}

07-24 09:21