Here is my situation: I load an object that contains a bi-directional parent child relationship into my database. Later, that object is loaded into my UI where changes can be made, including deleting any number of children from the child set. This modified copy of my object is then loaded using the saveOrUpdate method. However, when this modified copy is saved any deleted children remain in the database (new children being added to the set works fine). There are no errors being thrown throughout this process but I need these removed children to actually be removed from the database. I've pasted the relevant portions of my hibernate and java code below.
Parent hibernate config:
<bag name="specimenTypes" table="masterPkSpecimenType" cascade="all-delete-orphan" inverse="true">
<key column="runid"/>
<one-to-many class="SpecimenType"/>
</bag>
Child hibernate config:
<many-to-one name="reportCriteriaBean" class="ReportCriteriaBean" column="runid" not-null="true" />
Parent object code:
public List<SpecimenType> getSpecimenTypes() {
return specimenTypes;
}
public void setSpecimenTypes(List<SpecimenType> specimenTypes) {
this.specimenTypes = specimenTypes;
if(this.specimenTypes != null){
for(SpecimenType specType : this.specimenTypes){
specType.setReportCriteriaBean(this);
}
}
}
Child object code:
public ReportCriteriaBean getReportCriteriaBean() {
return reportCriteriaBean;
}
public void setReportCriteriaBean(ReportCriteriaBean reportCriteriaBean) {
this.reportCriteriaBean = reportCriteriaBean;
}
EDIT:
Apparently my problem is due to explicitly calling setSpecimenTypes() after I retrieve the parent object from the DB, and before I save the updated object back. the reason I am doing this is because, due to some dynamic List binding, I need the List to be a specific implementation of List (specifically apache's LazyList) when it is presented to the UI. However, when the object gets pulled from the DB it is not implemented in this way so I create a LazyList copy of the regular List that was pulled from the database and call setSpecimenTypes() to replace it with my newly populated LazyList. Does anyone know of a way for me to do this?