Following is my problem. I have a one-to-many relationship from Document to Diagram.
Mapping in Document.hbm
<hibernate-mapping> <class .....>
<set name="Diagramses" cascade="all-delete-orphan" inverse="true"> <key> <column name="DOCUMENT_ID" precision="22" scale="0" not-null = "true" /> </key> <one-to-many class = "com.qualcomm.pds.bf90.model.businessobject.Diagrams" /> </set> </class> </hibernate-mapping>
Mapping in Diagrams.hbm
<hibernate-mapping> <class .....>
<many-to-one name="document" class="com.qualcomm.pds.bf90.model.businessobject.Document" fetch="select" update="true" insert="true"> <column name="DOCUMENT_ID" precision="22" scale="0" not-null="true" /> </many-to-one> </class> </hibernate-mapping>
So, a document can have one or many diagrams. everything seems to be fine when I create a new Document and attach new Diagrams to it.
The problem comes when I try to delete one of the diagrams from a Document object - Below is the way I do it
//assume that documentHibObj has 3 diagrams attached to it(diagram1,diagram2 and diagram3).
Below is my code to update the Diagram set. documentHibObj.getDiagrams().clear(); documentHibObj.addDiagram(diagram1); documentHibObj.addDiagram(diagram2);
session.update(documentHibObj);
after the above the documentHibObj has only diagram1 and diagram2, but diagram3 is not getting deleted from the DB and hence when I query again for it I get 3 diagrams attached instead of the expected 2.
_________________ Regards,
Kiran C Sagi.
|