-->
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.  [ 7 posts ] 
Author Message
 Post subject: Oracle, Pagination and number of pages (redux)
PostPosted: Sat Apr 16, 2005 8:10 pm 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
Hibernate version:2.1.8

I had posted a question about a way to translate HQL to SQL. Here's why I'd like to get the underlying SQL.

Basically I need to display a paged table along with the total number of pages. Most of the pagination solutions for getting number of records from a Query object rely calling
Code:
scrollableResults.last();
scrollableResults.getRowNumber();


however as pointed out here http://www.hibernate.org/243.html, Oracle 9 does not have server side scrollable cursors and as a result the entire dataset is cached on the client. Our database has lots of records and our JVM would run out of memory with a driver that did client side caching when scrollableResults.last() is called.

The same URL also proposes a DoubleQueryPage class which executes a secondary count(*) query to get the number of results. The problem is that the implementation does a count(*) on the table corresponding to the primary entity class and this will return a wrong row count if the Query has filters or inner joins.

So I essentially want to follow the same approach except that I want to get the underlying SQL query from the Query object and the replace the substring till the first " from" string and replace it with "select count(*) ".

This would be much easier if the Query interface had a count() method.

If there is an easier way to accomplish this, please advise.

Thanks,
Sanjiv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 4:14 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
IMHO your count(*) will work only for extremely simple cases, hence its not the solution. You have to consider that there may be joins, projections, you should find some way to recover aliases and so on, so this would imply non trivial manipulations of the hql. In fact this shows that it is the wrong path.

I will update the code in the wiki as soon as I can.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 8:14 am 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
Thanks for the reply.

Quote:
IMHO your count(*) will work only for extremely simple cases, hence its not the solution. You have to consider that there may be joins, projections, you should find some way to recover aliases and so on, so this would imply non trivial manipulations of the hql. In fact this shows that it is the wrong path.


If I replace the first occurence of "selelct .... from [rest of query]" in the translated SQL of the provided HQL with "select count(*) from [rest of query]" it would already incorporate the joins, projections, filters etc., regardless of aliases present in the [rest of query] portion, wouldn't it?

Can you provide an example where it wouldn't work?


Quote:
I will update the code in the wiki as soon as I can.


Looking forward to checking this out.

Thanks,
Sanjiv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 8:58 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
I tried with several from clauses in the same query, and it seems to work anyway. So maybe this is the correct solution: if you can test it in detail, I will integrate it in the pagination code. Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 11:31 am 
Regular
Regular

Joined: Mon Sep 20, 2004 8:42 am
Posts: 58
Location: Boston, US
Thinking about it some more, I think I can do the string replacement on the HQL itself and avoid the HQL->SQL translation.

HQL queries can be of the form "select ... from Entity e [rest of hql]" or "from Entity e [rest of hql]"

So all I would need to do is change to HQL to the form

"select count(*) from Entity e [rest of hql]"

Sanjiv


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 18, 2005 9:33 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
I have built a HQL query builder to deal with this sort of issue for HIbernate 2.x. Don't need to now that Hibernate 3.x QBE supports count() etc etc etc.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Apr 19, 2005 3:42 am 
Beginner
Beginner

Joined: Fri Aug 29, 2003 10:01 am
Posts: 34
Location: florence, italy
Quote:
I have built a HQL query builder to deal with this sort of issue for HIbernate 2.x.


Could you give a pointer to this ?

Quote:
Don't need to now that Hibernate 3.x QBE supports count()


I will check it; but in pagination we need to support the entire spectrum of hql queries.

Thanks


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