-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 
Author Message
 Post subject: Problem using one-to-many relationship
PostPosted: Tue Oct 06, 2009 4:28 am 
Newbie

Joined: Fri Apr 27, 2007 9:17 pm
Posts: 2
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.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.