-->
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: Improve Paging
PostPosted: Tue May 29, 2007 1:16 pm 
Newbie

Joined: Fri Sep 17, 2004 4:29 pm
Posts: 10
Hibernate version: Hibernate 3.2.4

Name and version of the database you are using:mySql 5.0


Hi everyone, I'm locking for a fast paging method. I have a table with 3'000.000 of rows, it has one pk and without fk. I've used criteria.setFirstResult and setMaxResults methods like it shows:

Code:
public List selectTABLE_ORIGIN(String pUser, int PageSize, int PageId)throws ServiceException
{
   StatelessSession sess_w = getStateLessSession(pUser);
   int start_w = (PageId-1)*PageSize;
   int rowNum_w = PageSize;
   try
   {
  Criteria criteria_w = sess_w.createCriteria  (TABLE_ORIGIN_Impl.class);
   List list_w = criteria_w.setFirstResult(start_w).setMaxResults (rowNum_w).list();
return list_w;
}catch(Exception e){
throw new ServiceException(e.getMessage(), e);
}finally{
closeSession();
}
}


I'm calling this method to get the rows, the PageZise is 500 and the PageId goes growing each time i call the method. The 10 fist times are fast, but it goes down after that and the performance is bad. i've taken the time and i could see that it was taking 13 minutes to get 100.000 rows, it means that 3'000.000 would take more or less 6 hours and obviously it can not be possible.

So i tried to implement ScrollableResults in order to take advantage of server-side cursors like it shows:

Code:
public void selectTABLE_ORIGINAndPut(String pUser)throws ServiceException
{
StatelessSession sess_w = getStateLessSession(pUser);
try
{
String hql = "from TABLE_ORIGIN_Impl";
Query query = sess_w.createQuery(hql);
ScrollableResults registries_w = query.scroll(ScrollMode.FORWARD_ONLY);
while ( registries_w.next() )
{
TABLE_ORIGIN table_w = (TABLE_ORIGIN) registries_w.get(0);
}
}catch(Exception e){
      e.printStackTrace();
      throw new ServiceException(e.getMessage(), e);
   }finally{
      closeSession();
   }

}


but it throws a java.lang.OutOfMemory error and I couldn't get any registry.

can someone tell me if there is a better option to do that or if there is any mistake in my code?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 01, 2007 12:36 pm 
Newbie

Joined: Fri Sep 17, 2004 4:29 pm
Posts: 10
Hi again, I've researched about Scrollable and I've made test over Mysql, postgres and oracle. I found out that Scrollable doesn't work with neither mysql nor postgress, when I call query.scroll(), It throws a java.lang.OutofMemory. However, I made the same test over oracle and it seems to work fine; it takes 12 minutes reading 3'000.000 rows. this performance is good for me.

thanks and see ya


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.