-->
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: Loading a list of objects by id
PostPosted: Sun Jan 03, 2010 3:58 pm 
Newbie

Joined: Sun Jan 03, 2010 3:12 pm
Posts: 2
Hi,

I'm currently using a Sphinx search engine to search through some rows in a table. This then returns a list of 20 ids to be shown on my listings page.

What I'd like to be able to do is use Hibernate to return the full objects for these ids. Many of the the more popular objects will be stored in the secondary level cache and it occured to me that in theory, for many searches I should be able to retrieve these objects without hitting the database at all.

But how to do it?

I've tried an HQL query with an IN (:idList) clause but this does hit the database even though in theory it doesn't need to. I've also tried a similar thing with a criteria query but this does the same.

I could loop though the list and do 20 load()s but this seems pretty inefficient, especially when the cache isn't warmed up.

Is there a better way of loading a list of objects where the ids are known?

Many thanks
Ian


Top
 Profile  
 
 Post subject: Re: Loading a list of objects by id
PostPosted: Sun Jan 03, 2010 4:36 pm 
Newbie

Joined: Sun Jan 03, 2010 3:12 pm
Posts: 2
Hurrah - figured it out myself.

I set my class mapping to:

<class lazy="true" batch-size="20">

Then, I loop through 20 load()s. This then loads what it can from the cache, and loads the rest from the database using a single query with an IN clause. It looks like it was the batch-size that I was missing.

I have to say, Hibernate is unbelievably powerful!

Ian


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.