I have PolicyDO and PolicyDocumentDO.relation between them is as follows
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>
When ever I tried to query something from database like below
session = sessionFactory.openSession();
Query query = session.createQuery(strBuff.toString());
List listQuery = query.list();
I get following error
org.hibernate.HibernateException: A collection with cascade="all-delete-orphan" was no longer referenced by the owning entity instance:
dataobjects.policy.PolicyDO.listPolicyDocumentDOList
So after googling I did following changes while setting listPolicyDocumentDOList in PolicyDO
public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
policyDocumentDOList.clear();
policyDocumentDOList = list;
}
Then also I am getting above error. What else I can do to solve this error. Thanks
change
public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
policyDocumentDOList.clear();
policyDocumentDOList = list;
}
to
public void setListPolicyDocumentDOList(java.util.List<PolicyDocumentDO> list) {
policyDocumentDOList.clear();
policyDocumentDOList.addAll(list);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With