-->
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: One-to-many Collection question
PostPosted: Fri Jan 09, 2004 4:19 pm 
Beginner
Beginner

Joined: Thu Nov 06, 2003 10:04 pm
Posts: 22
I have a question about one-to-many collections. I have the following two classes.
Code:
<class name="Parent" table="parents">

  <key>
      <column name="parent_id", sql-type="char(36)"/>
  </key>

  <list name="children" inverse="true" cascade="all-delete-orphan">
       <key>
           <column name="parent_id" sql-type="char(36)"/>
       </key>
       <index column="index"/>
       <one-to-many class="Child"/>
  </list>

</class>

<class name="Child" table="children">

   <key>
       <column name="child_id" sql-type="char(36)"/>
   </key>

   <many-to-one name="parent" class="Parent">
       <column name="parent_id" sql-type="char(36)" not-null="true"/>
   </many-to-one>

</class>


Now for a Parent instance that had been saved in a previous session, I make some changes in a UI tier, like adding new Children, modifying some existing Children and removing some other exisiting Children from the Parent's children collection.

Now in order to saveOrUpdate() this Parent instance in a new Session, do I simply do session.saveOrUpdate( parent )? If so, will Hibernate know which Children are new, which ones modified and which ones to delete from the database?

Or would I have to manually iterate over the children collection in the dao tier to see which ones to saveOrUpdate and which ones to delete?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jan 10, 2004 3:26 am 
Expert
Expert

Joined: Fri Nov 07, 2003 4:24 am
Posts: 315
Location: Cape Town, South Africa
Quote:
do I simply do session.saveOrUpdate

Yes
Quote:
If so, will Hibernate know which Children are new, which ones modified and which ones to delete from the database

Yes. The way in which this is implemented varies according to the type of collection that you are using. See section 13 of the reference - Understanding collection performance.


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.