-->
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.  [ 5 posts ] 
Author Message
 Post subject: number of rows before real query
PostPosted: Tue Feb 17, 2004 1:56 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
1) I'm sorry I keep on posting but I can't use the search on the forum...
Is there a way to look for a string instead of a boolean expression?
It's hard to look for "number of rows" using "number and rows"...

2) I have to divide a list of objects into "pages" of data.
I'm using setMaxResults and setFirstResult, but the very first time
the user asks for the list I want to know the total number of rows.
What's the faster method?

a)
if (firstTime) {
totrows = query.list().size() // without setMaxResults or setFirstResult
}
query.setMaxResults(..)
query.setFirstResult(..)
List mylist = query.list() // re-query

b) use another query with "select count(*)" just before the "real" query:
if (firstTime){
totrows = ((Integer)query2.iterate().next()).intValue()
}

//now the "normal" query
query.setMaxResults(..)
query.setFirstResult(..)
List mylist = query.list()


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 2:41 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Would say 2b

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 2:53 pm 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
I suppose that in b) I have to re-set all my bind variables.
Or there is another method? I'm asking because the class
that "limits" the query doesn't "know" the values of the bind variables...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 17, 2004 3:33 pm 
Hibernate Team
Hibernate Team

Joined: Sun Sep 14, 2003 3:54 am
Posts: 7256
Location: Paris, France
Sounds like a weird design. I want to know the size of something but I don't really know what.

_________________
Emmanuel


Top
 Profile  
 
 Post subject:
PostPosted: Wed Feb 18, 2004 4:40 am 
Beginner
Beginner

Joined: Tue Jan 27, 2004 8:33 am
Posts: 29
The thing is I have something like:

Query query = ....

limit.limit(query);

where limit is an interface. That's way it doesn't know "what" to limit.
I'll change my design if there is no way to get the parameters passed to
a Query.


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