-->
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.  [ 4 posts ] 
Author Message
 Post subject: sess.save()
PostPosted: Mon Dec 03, 2007 11:59 am 
Newbie

Joined: Thu Nov 15, 2007 9:52 am
Posts: 8
I don't understand why I get the associated child-objects of an object loaded without loading them explicit with sess.load() - thanks to hibernate - whereas I have to save new added child-objects explicitly with sess.save().

Why is it necessary to save them explicitly with sess.save() whereas loading works automatically when objects get needed?

Is it possible to get added child-objects saved automatically with the help of the mapping-file?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 1:16 pm 
Expert
Expert

Joined: Thu May 26, 2005 9:19 am
Posts: 262
Location: Oak Creek, WI
Hi,

When u load the parent object with lazy loading set to false, you will have child objects attached with the parent.

And saving your parent object will also save your child object. look into the below link for one-to-many associations.
http://www.hibernate.org/hib_docs/v3/re ... tional-12m
http://www.hibernate.org/hib_docs/v3/re ... tional-m21

_________________
RamnathN
Senior Software Engineer
http://www.linkedin.com/in/ramnathn
Don't forget to rate.


Top
 Profile  
 
 Post subject: answer brings up new question
PostPosted: Mon Dec 03, 2007 2:46 pm 
Newbie

Joined: Thu Nov 15, 2007 9:52 am
Posts: 8
Thank you ramnath, your answer helped and I've rated it.

But this brings up a new question.
I need the lazy-loading feature, because I have a huge number of child-objects associated (about several thousands).
With the lazy-load I aimed to load only the first "level" and to load the deeper "levels" only if needed.
Is there another way or will I have to save and update objects explicitly with sess.saveorupdate(), when I use the lazy-load-feature?
Or maybe I've misunderstood the lazy-feature at all?


Top
 Profile  
 
 Post subject: Use the cascade settings
PostPosted: Mon Dec 03, 2007 4:09 pm 
Regular
Regular

Joined: Wed Dec 21, 2005 6:57 pm
Posts: 70
Cascade settings will determine how the object graph is walked to automatically save objects.

Beware bi-directional associations however, because the cascade settings will determine how the graph is walked to see what should be saved, but the 'inverse' attribute will determine what actually causes a relationship to be persisted. So sometimes the cascade setting can cause a child object to be saved, but the child will not have the non-inverse side of the association and will therefore not be associated with its parent.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 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.