-->
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.  [ 2 posts ] 
Author Message
 Post subject: Global fetch strategy for list
PostPosted: Sat Mar 24, 2007 7:21 am 
Newbie

Joined: Wed Aug 16, 2006 6:29 pm
Posts: 9
Hi-
I'm using the sample code for caveatemptor-native-061211 to understand the fetching strategy when navigating a one-to-many list association. What I saw was doesn't reconcile with what I expected. Here is what I did. I removed batch-size="10" from "bids" in Item.hbm.xml. Then I wrote code to load an item and get a bids like this:

Code:
ItemDAO itemDAO = daoFactory.getItemDAO();
Item item = itemDAO.findById(1L, false);
List<Bid> bids = item.getBids();

Bid bid = bids.get(1);
log.debug("Bid amount: " + bid.getAmount());

I expected to see a query for loading the bid at index 1. Instead I saw a query loading all bids for the item. Since collections are lazy loaded by default in Hibernate core and without a batch-size property wouldn't there be a separate query each time a bid is accessed? Am I missing anything else? I realize what I see is more efficient but I'd still like to understand it.

thanks,
Rossen


Top
 Profile  
 
 Post subject:
PostPosted: Sat Mar 24, 2007 8:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
This is not how batch fetching for collections works. It's not about loading a subset of the list elements in batches. It's about loading _the same collection_ for _other items_ you have loaded. If you retrieve only one item, no batch fetching of several collections will occur.

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


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