-->
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.  [ 2 posts ] 
Author Message
 Post subject: Deleting a record from One -to - Many Relationship
PostPosted: Wed Aug 13, 2008 10:03 am 
Newbie

Joined: Wed Aug 13, 2008 8:58 am
Posts: 1
I have 2 database tables (A,B), relationship between those 2 tables is One record of table A has reference to many records of table B,(One - to - Many)
When i load up my application it loads the records of table A to a drop-down list, from there if i select any record of table A, it loads the relavent records of table B (as Objects of cause) to temp List, from there i modify/add new / and delete records from/to that temp list. Now my problem is after all the playings are done, i want to update that particular record of Table A in the database table with only one call to data base using hibernate. In other words if i click save button, it has to delete records of table B (if i have already deleted that record from that temp list), add new records (if i have added new records to that temp list), modify records of table B(if i have modifyed current records of temp list) with only one call to database.
How do i do this using hibernate?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 13, 2008 10:53 am 
Newbie

Joined: Tue Jan 15, 2008 2:11 pm
Posts: 5
I think the following example may help you:
http://www.hibernate.org/hib_docs/v3/re ... d-cascades

Basically all you have to do is:
    open a session
    reattach the objects (by a call to update or merge)
    flush the session (to commit the transaction)
    close the session


the call to update/merge should automatically find which elements of B were already there, which are new and which disappeared.

note: The B elements must have an identifier attribute for the update/merge to work.

Hope that helps.


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

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.