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.  [ 15 posts ] 
Author Message
 Post subject: Efficient way to process a large table
PostPosted: Fri Jun 18, 2004 5:53 pm 
Newbie

Joined: Thu Apr 01, 2004 3:36 pm
Posts: 13
Location: New York
Hi guys,

I need to iterate over the records of a large table (a couple mil records) and I'm trying to figure out an efficient way to do it in hibernate.

1. using query.list() brings everything in memory (not scalable)
2. using query.iterate() or query.scroll() performs N + 1 queries (inefficient)

I was looking for some functionality similar to navigating a JDBC result set which reads data as you advance.

I terms of performance I would assume there is a big difference between using query.iterate() and JDBC resultset navigation.

How would you guys approach this issue?

Thanks,
Bogdan Calmac.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 18, 2004 6:28 pm 
Beginner
Beginner

Joined: Tue Feb 10, 2004 2:30 pm
Posts: 25
That many rows is troublesome, I'd likely drop to a stored procedure to execute it on the server.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 19, 2004 9:59 am 
Newbie

Joined: Thu Apr 01, 2004 3:36 pm
Posts: 13
Location: New York
Well, the actual processing is provided by a different layer. I only iterate through the data and pass it to processing through an interface.

I guess I have to fallback to JDBC. But that means that I'm gonna have to populate the POJOs myself.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 19, 2004 10:55 am 
Beginner
Beginner

Joined: Mon Jun 07, 2004 4:21 pm
Posts: 44
Location: Boston
Does this help?

http://forum.hibernate.org/viewtopic.php?t=930257


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 19, 2004 10:59 am 
Newbie

Joined: Thu Apr 01, 2004 3:36 pm
Posts: 13
Location: New York
Yes I saw that, Gavin said that scroll() should be implemented to fetch all the data rather than the IDs, but it's not currently implemented. On JIRA there is no indication for a plan to implement it.

Thanks,

Bogdan.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 19, 2004 11:13 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
It is one of the minor features that was proposed for Hibernate3.

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


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 12:55 pm 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
Christian, this is an important feature for our application -- and any application that does large batch processing, I would imagine. Is there any official way to vote/voice support for v3 features? Or is that what I just did? ;)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jul 08, 2004 12:58 pm 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
I think this has already been implemented, or at least, made its way on the TODO list. We will open a new JIRA project for Hibernate3 soon.

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 09, 2004 12:39 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
It is not yet implemented, and probably won't make it into 30 alpha. I hope it will be there for 3.0 beta 1.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 1:49 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 3:00 pm
Posts: 1816
Location: Austin, TX
Just to round out this discussion, this has been implemented both in versions 2 and 3...


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 4:53 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
So this will be included in a future release on the 2.1.x codeline, hopefully 2.1.5?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 5:36 am 
Hibernate Team
Hibernate Team

Joined: Mon Aug 25, 2003 9:11 pm
Posts: 4592
Location: Switzerland
Right

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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jul 23, 2004 11:39 am 
Regular
Regular

Joined: Fri Dec 12, 2003 2:09 pm
Posts: 84
Location: San Francisco, USA
What can I say... you guys rock!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 13, 2005 3:46 am 
Newbie

Joined: Tue Jun 21, 2005 10:23 am
Posts: 1
Location: Munich, Germany
Howdy,

I came across this thread, cause we found out as well that Hibernate 2.1.7 with DB2 produces a somewhat slow query using "rownumber()" in DB2-SQL when you use setMaxResults(n).

Using scroll() to obtain a ScrollableResults however did not do it for us, like discussed previously in this thread. The query (the invocation of query.scroll()) would roughly take the same amount of time like when we used setMaxResults(n) and invoked query.list().

Using the following code fragment did the job for us:

Code:
            Iterator it = query.iterate();
            int i = 0;
            result = new ArrayList();
            while ((i < maxResults) && (it.hasNext()))
            {
               i++;
               TransferObject to = (TransferObject) it.next();
               result.add(to);
            }


Maybe this helps someone!

Cheers,
Stephan


Top
 Profile  
 
 Post subject: Selecting into the cursor
PostPosted: Tue Jan 13, 2009 8:29 am 
Regular
Regular

Joined: Tue Jun 03, 2008 1:12 pm
Posts: 84
Location: germany
double post


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