-->
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: Preload the query cache?
PostPosted: Mon Apr 18, 2005 3:02 am 
Newbie

Joined: Sun Apr 17, 2005 1:56 am
Posts: 2
I'm experimenting with the auction mapping in the hibernate examples. I'd like to load all the auction items and bids into memory with a minimum of queries.

I do one query: load all the AuctionItems:

Session session = factory.openSession();
List auctionItems = session.createQuery("from AuctionItem").list();

Then I iterate over the auctionItems, getting their bids (because it's a lazy collection), generating sql (in hibernate 3)

...
Hibernate: /*load one-to-many org.hibernate.auction.AuctionItem.bids*/select bids0_.item as item__, bids0_.id as id__, bids0_.id as id0_, bids0_.amount as amount1_0_, bids0_.`datetime` as datetime1_0_, bids0_.bidder as bidder1_0_, bids0_.item as item1_0_, bids0_.isBuyNow as isBuyNow0_ from Bid bids0_ where bids0_.item in (?, ?, ?, ?, ?, ?, ?, ?)
Hibernate: /*load one-to-many org.hibernate.auction.AuctionItem.bids*/select bids0_.item as item__, bids0_.id as id__, bids0_.id as id0_, bids0_.amount as amount1_0_, bids0_.`datetime` as datetime1_0_, bids0_.bidder as bidder1_0_, bids0_.item as item1_0_, bids0_.isBuyNow as isBuyNow0_ from Bid bids0_ where bids0_.item in (?, ?, ?, ?, ?, ?, ?, ?)
[...]

Where it's preloading 8 bids and trying to be efficient.

But I want to avoid this database hit (say I've got 100k bids). so before I start iterating over AuctionItems, I do the following query:

session.createQuery("from Bid").list();

Which should load all the bids into a cache. But it doesn't.. the queries I was trying to avoid still happen.

I did some reading, and it seems that caches key only by primary key. The item on a bid is a foreign key, and it's nonunique.

So is there any way to be both efficient and idiomatic about this?

Thanks,

Ranjan Bagchi


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.