-->
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: ScrollableResults perf question
PostPosted: Thu Mar 12, 2009 6:07 pm 
Newbie

Joined: Wed Mar 14, 2007 2:14 pm
Posts: 8
Hi, All,
To deal with a large result set(0.5~1M), I used this code fragment:
============================
Query query = getSession().createQuery("select p.lastName, p.firstName from Person as p where p.age= :age");
query.setLong("age", 21);
ScrollableResults res = query.scroll(ScrollMode.FORWARD_ONLY);
count = 0;
while (res.next())
{
String lName= res.getString(0);
String fName= res.getString(1);
//TODO biz logic starts here

count++
// clear cache to avoid memory issue
if ( count % 1000 == 0 ) {
getSession().flush();
getSession().clear();

}

}
res.close();
===============================

Two questions:
(1). Anything I can do here to make this loop fast? Current it is 3~4 times slower than that a single query to read all results into a list(consuming huge memory)

(2). Can I get Person object directly in ScrollableResults instead of these primitive types?

Platform: Hibernate 3.2, JDK-1.5, Oracle 10G, and XP/sp3 with 3G memory

Any help is greatly appreciated!

-Herbert


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.