-->
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: Performance issues
PostPosted: Wed Aug 17, 2005 1:13 pm 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Hi group,

I have a performance issue and really need a solution. I have a database and one of the tables contains about 100000 records which are child records of a parent table. Within my code the parent and child records are connected as following:
Code:
child.setParent(parent);
parent.add(child);


The problem is that when I add the child record to the parent object, all already existing child records are loaded from the database by Hibernate (lazy loading). This is the problem of my performance issue. I'm looking for a solution that I can only add the newly created child to the parent without Hibernate is loading the already existing from the database.

Could somebody please help me to solve this problem?

Thanks in advanc,
ErBruijn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:35 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
Set lazy=true and use List or IdBag as the collection type. Use lazy initialization so that chilren won't be loaded into memory.
Using IdBag or List is efficient to add new items without hitting database since the Collection.add(...) always return true.

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:38 pm 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Jason, thanks for the quick anwser. The next question that comes into my mind is why should I ever use <set>? When <bag> is much efficienter?!

erbruijn.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:40 pm 
Beginner
Beginner

Joined: Wed Apr 13, 2005 2:03 pm
Posts: 34
If I recall, set ensures uniqueness of entities, while bag will let you put multiple copies of the same entity in the bag.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:42 pm 
Newbie

Joined: Tue Mar 09, 2004 10:51 am
Posts: 16
Sounds assumable... THANKS FOR YOUR QUICK RESPONSES AND TIME!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 1:47 pm 
Beginner
Beginner

Joined: Tue Aug 16, 2005 11:06 pm
Posts: 46
No problem! Don't forget to rate :)

_________________
Jason Li
Don't forget to rate:)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Aug 17, 2005 2:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
You could also try lazy="extra" in HB 3.1beta2.


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.