-->
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.  [ 7 posts ] 
Author Message
 Post subject: updating collection state
PostPosted: Fri Sep 03, 2004 3:22 am 
Newbie

Joined: Fri Jul 23, 2004 2:36 am
Posts: 3
I have a question about collections in one to many relationship
my concern is extra queries and how to avoid them in a
desktop application.

for example Parent has more children

Parent p;
child c;

when I save Child and it has a parent defined
after flushing Parent in my session is not updated
so I update p.getChildren().add(c);

does any one know will this cause the collection to be
dirty and be saved upon next flush

I'm not sure if I explained my problem well,
but my goal is to keep the getChildren() collection
up-to-date and avoid unnecessary database access


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 3:25 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
need more info, read the red box again

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 3:42 am 
Newbie

Joined: Fri Jul 23, 2004 2:36 am
Posts: 3
I'm not posting a bug, but a general question.


Just need to know:

in the parent child relationship

should I expect Hibernate if i call
c.setParent();
to add the child "c" to the parents collection "p.getChildren()"


I tried something like this and it works only when I restart the application


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 3:58 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Nope, you should not expect that. Hibernate associations behave identically to ordinary Java associations.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 4:03 am 
Hibernate Team
Hibernate Team

Joined: Thu Dec 18, 2003 9:55 am
Posts: 1977
Location: France
Quote:
c.setParent();
to add the child "c" to the parents collection "p.getChildren()"


no, a best practice in java about bidirectionnal association is to manage both sides of the association, methods like addChild & removeChild are very usefull for this

_________________
Anthony,
Get value thanks to your skills: http://www.redhat.com/certification


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 8:48 am 
Newbie

Joined: Fri Jul 23, 2004 2:36 am
Posts: 3
thank you :)

now the second part of my question:

after
c.setParent();
and
p.getChildren().add(c);

If I save parent .. cascading will save the child also,
but I have little knowledge on how it happens actually
(I mean query count)


is there a link to an article that considers optimizing
while saving these objects (there is some in documentation),
or should I watch the log for queries and research it
for my case


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 03, 2004 10:21 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
http://hibernate.org/155.html


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