-->
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.  [ 1 post ] 
Author Message
 Post subject: Loading 4 whole assoc. Collections VS 4 individual DB hits
PostPosted: Mon Jul 27, 2009 6:43 am 
Newbie

Joined: Mon Feb 16, 2009 2:27 pm
Posts: 7
Which is the best method to use to only load a limited amount
of items from an assocated collection?

The idea is to only load a certain ammount of objects.
I have one User object with 4 collections associated with it.
But I only want to display 20 items from each collection.


Method 1 : Use Lazy-loading of the collections.

Code:
User user = userService.findUserById(userId);
Product product = user.getProducts();
Comment comment = user.getComments();
Friends friends = user.getFriends();


Full Class+DAO code is here,http://forum.springsource.org/showthread.php?t=75099
The Collections are loaded in the same Hibernate session
but the whole collection is loaded.



Method 2
: http://forum.springsource.org/showthread.php?t=65836

Hit the database each time to load a certain collection.
and set the maximum amount of results to be returned in each of the DaoImpl.

Code:
User user = userService.findUserById(userId);
Product product = productService.findProductsById(userId);
Comment comment = commentService.findCommentsById(userId);
Friends friends = friendsService.findFriendsById(userId);

session.createQuery(xxxxx).setFirstResult(0).setMaxResults(15).list();



Gets the required amount, but a new Hibernate session
and database hit is required each time.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.