-->
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.  [ 4 posts ] 
Author Message
 Post subject: How to order a resultset without OutOfMemory errors....
PostPosted: Wed Oct 04, 2006 4:45 pm 
Beginner
Beginner

Joined: Sun Sep 24, 2006 11:48 am
Posts: 21
How do you order a resultset without causing OutOfMemory exceptions?

In my case I just want to have 20 results within a paged resultset....

Code:
public List<User> getLatestMembers() {

      Criteria criteria = _session.createCriteria(User.class);
      criteria.setMaxResults(20);
      List<User> users = criteria.list();
      return users;
   }


works fine....but once I want to order the users by the registration date I get this OutOfMemory exception:

Code:
public List<User> getLatestMembers() {

      Criteria criteria = _session.createCriteria(User.class);
           criteria.addOrder(Order.desc("lasttime"));
      criteria.setMaxResults(20);
      List<User> users = criteria.list();
      return users;
   }


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 04, 2006 7:14 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
forgotyourusernameagain2,

The code change does not seem to be related to the error. Maybe you can post more information, for example some levels of the strack trace or similar...?

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 8:36 am 
Newbie

Joined: Thu Dec 21, 2006 8:06 am
Posts: 8
Hello,

I think your problem come from setMaxResults function.

Here is the request without it:
select field from table order by field

And then with it:
select * from ( select field from table order by field ) where rownum <= ?

This "select * from" is a performance killer when you are using order by...

But I don't know how to make hibernate generate the right request:
select field from table where rownum <= ? order by field )


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 02, 2007 10:03 am 
Newbie

Joined: Thu Dec 21, 2006 8:06 am
Posts: 8
hello!

first
select field from table where rownum <= ? order by field
order only on the returned result! so that's not good.

So I think that you just need an index in the database on the field you want to order by.


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