I have the following one to many bidirectional relationship defined.
@OneToMany(cascade = {CascadeType.ALL}, fetch = FetchType.LAZY, mappedBy = "journal")
@Cascade(value = org.hibernate.annotations.CascadeType.DELETE_ORPHAN)
@OrderBy(value = "sequence")
public List<JournalLine> getJournalLines() {
return this.journalLines;
}
If i execute the following:
beginTransaction();
Journal found = DAOFactory.DEFAULT.getJournalDAO().findById(new Long(187007),false);
found.getJournalLines().clear();
found.setJournalStatus(JournalStatus.DELTED);
endTransaction();
It fails with:
org.hibernate.StaleObjectStateException: Row was updated or deleted by another transaction (or unsaved-value mapping was incorrect): [com.catlin.da.insuranceledger.model.JournalLine#5]
If i drop the last line:
beginTransaction();
Journal found = DAOFactory.DEFAULT.getJournalDAO().findById(new Long(187007),false);
found.getJournalLines().clear();
// found.setJournalStatus(JournalStatus.DELTED);
endTransaction();
It works
Or if I drop the DELETE_ORPHAN it also works?
It seems that setting CascadeType.ALL in fact are deleting children by just clearing the collection. No need to explicitly deleting the children!!! In other words the DELETE_ORPHAN is not nessesary????
|