-->
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.  [ 9 posts ] 
Author Message
 Post subject: get the next 50
PostPosted: Tue Oct 02, 2007 11:47 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
I know you can set restriction to get only 50 out of a large set.

Criteria crit = sess.createCriteria(Cat.class);
crit.setMaxResults(50);
List cats = crit.list();

But, after that, how do you get the next 50?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 2:34 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Hm. I guess something like:

Code:
   Criteria crit = sess.createCriteria(Cat.class);
    crit.setMaxResults(size);
    int start = 0;
    final int size = 50;
   {
      crit.setFirstResult(start);
      List cats = crit.list();
      start += size;
      //process cats
    } while (cats.size() == size);


Regards,
Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Wed Oct 03, 2007 1:17 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
would I have found this call in the " Relational Persistence for Idiomatic Java" documentation, or only in the api doc?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 04, 2007 3:18 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Or you can use scroll ?

http://www.hibernate.org/hib_docs/v3/re ... -scrolling

Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 08, 2007 8:24 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
Thanks. both replies are excellent.

this thread is not quite yet concluded. what happens when you are fetching the child list of an object?

I am using lazy fetching to start with, and calling

Hibernate.initialize(childList);

when I need to get the child list.

how do you control the list size in this case?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 09, 2007 3:28 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
What do you mean under controlling the list size?

Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 12, 2007 7:01 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
if you have 1000 children in the list, and you don't want to fetch all of them out of the database, can you limit the fetched child list to the first 50, as is done with pagination using query.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 13, 2007 12:27 am 
Regular
Regular

Joined: Sun Sep 30, 2007 7:51 pm
Posts: 93
Well, I don't think you can control the child list of parent in such way. You can set fetch size, but I think once someone needs the child list, it will be initialized completely.

What I would do is not having the child list, but some DAO layer, and in case you need to iterate the child list, it will scroll the query (control the size).

Pavol


Top
 Profile  
 
 Post subject:
PostPosted: Sat Oct 13, 2007 10:54 pm 
Beginner
Beginner

Joined: Mon Sep 03, 2007 4:25 pm
Posts: 24
that's what I pretty much concluded on my own. thanks for confirmation.


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