-->
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.  [ 6 posts ] 
Author Message
 Post subject: Lazy Loading and Performance
PostPosted: Tue Jan 20, 2004 7:32 pm 
Newbie

Joined: Tue Jan 20, 2004 6:34 pm
Posts: 1
We are looking at using Hibernate for a large system, and a concern has been raised around the potential negative performance impact of lazy loading.

Lazy loading obviously is a very beneficial concept, but I suspect that if you know you need an object and its related objects that use lazy loading would be slower than issuing a single select statement that joins the tables containing the data.

So, for instance, if I had an Account object that has a collection of Transaction objects -- I could load an Account with a collection of Transaction objects using a join. Or, I could load the Account and when I try to use the Transactions it would go back to the database and retrieve them.

Has anyone done any analysis of the performance difference (in the situation where you need both objects)? I am interested in how costly the extra trip to the database is and whether it should be a concern.

BTW: I know we can do joins with Hibernate while still supporting lazy loading, but I am more concerned about it because sloppy developers (we will have a lot of developers) might not use joins where it makes sense, instead relying on the lazy loading to give them what they need -- I am interested in whether this could become a performance problem.

Thanks!

Randy


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 20, 2004 7:47 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
It is allways a tradeof of result set size versus multiple queries, there is no definite answer, all depends on your use case. Note however that you most likely must do lazy loading at some point in the object graph, otherwise you quickly get into situations where the complete object graph is fetched for every load due to non-lazy associations.

For sloppy developers: Note that you can use outer-join="true" in the mapping file, to force join loading for certain associations.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 1:42 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Much more important, Hibernate supports both lazy and eager loading not only with "defaults" in the mapping metadata, but can efficiently do both at runtime. You can control the graph of objects that should be fetched at a very fine grained level.

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 1:43 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
And note that we can't obviously do much about developers not using the the appropriate options ;)

_________________
JAVA PERSISTENCE WITH HIBERNATE
http://jpwh.org
Get the book, training, and consulting for your Hibernate team.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 9:29 am 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
I agree christian, using sloppy developpers and wanting advanced Hibernate usage is a bit hard. Having an Hibernate expert in the team, is the solution I use.

Otherwise, use the 80%-20% rules to choose the best static mapping/

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jan 21, 2004 3:57 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
Having an Hibernate expert in the team, is the solution I use


I agree with this. If you seperate data access code into DAOs, it should be easy for the "data access / Hibernate expert" to come along later and tune the queries and mappings. Its actually an advantage of ORM that performance is "easy" to adjust at a late stage of development.


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