-->
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.  [ 10 posts ] 
Author Message
 Post subject: HQL, select TOP
PostPosted: Mon Oct 16, 2006 10:01 am 
Newbie

Joined: Mon Oct 16, 2006 9:56 am
Posts: 10
Hibernate version:1.02

Name and version of the database you are using: SQL 2000

Hello All,

Is it possible to transfer this sql to HQL?

select count(*) from (select top 100 * from js_point order by createddate) as point

Some property of my POCO:

Point.ID
Point.Name
Point.CreatedDate

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 2:09 pm 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I must be missing something - wouldn't that always return 100?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 2:27 pm 
Newbie

Joined: Mon Oct 16, 2006 9:56 am
Posts: 10
Dear K-dub,

there is possible that records are less than 100.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 3:20 pm 
Contributor
Contributor

Joined: Sat Sep 24, 2005 11:25 am
Posts: 198
Get the count back, set to 100 if it is over 100.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Oct 16, 2006 11:09 pm 
Newbie

Joined: Mon Oct 16, 2006 9:56 am
Posts: 10
that's my HQL

select count(pt) from ( select ptt from Point ptt order by ptt.CreatedDate desc)

I get an exception

Exception Details: NHibernate.QueryException: in expected: select [select count(pt) from ( select ptt from JasonSoft.Model.Point ptt order by ptt.CreatedDate desc)]


How to write the HQL like the SQL above?
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 2:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Why don't you just do "select count(*) from Point pt"? Ordering doesn't change the count anyway. Or are you going to expand this query further?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Oct 17, 2006 7:46 am 
Newbie

Joined: Mon Oct 16, 2006 9:56 am
Posts: 10
Sure...

Firstly, the point table store information about one place's city, longitude、 latitude、description、createddate、lastupdated..ect..

I am going to create a web application that integrate GoogleMap.

There are two features of the application.

Get the newest 100 points that were created by users.
Get the lastest 100 points that were modified by users.

moreover, the result can be filtered by city again.

I am planning to display the data with DataGrid.
Also, I am using custom pager (that's problem...I need to do the pager by myself, not Datagrid. The reason I do that because of performance. I don't want datagrid to bind all the records. I just want the grid to display the records depend on what the page is...)

Therefore, I need to give count of total records to datagrid.

In SQL way, I do this way

select count(*) from (select top 100 * from js_point order by createddate) as point

select count(*) from (select top 100 * from js_point order by lastupdated) as point

I have tried something as following...however, no lucky...

select count(*) from js_point order by createddate
(or with group by...)


Hope that's useful...thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Oct 19, 2006 5:57 pm 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I found that "select count(m) from MyObject m" doesn't work, but if you do it based on the id of the object it'll be fine - "select count(m.id) from MyObject m"

Not sure if this will help, but it's worth a shot.

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 20, 2006 1:02 am 
Newbie

Joined: Mon Oct 16, 2006 9:56 am
Posts: 10
Yes, you are right...

but the problem is order by...
that's the reason I'm using subquery...

select count(*) from (select top 100 * from js_point order by lastupdated) as point

I am going to do this in SQL way, and give up HQL
thank you


Top
 Profile  
 
 Post subject:
PostPosted: Fri Oct 27, 2006 5:51 am 
Newbie

Joined: Fri Oct 27, 2006 5:20 am
Posts: 1
I too have the same problem. When using Hibernates paging functionality I sometimes need to show the total amount of hits (as if the query wasn't paged). Some of theese HQLs dosn't translate to any working count-query.

Is there a way to make the thread starters query work? I.e. count the result of any given generic HQL query.


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