-->
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.  [ 8 posts ] 
Author Message
 Post subject: Nested query doesnot work
PostPosted: Wed Jan 30, 2008 9:28 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
Hi, i am trying to do something of the kind:

select a, count(b)
from (select limit 0 20 * from T order by c desc)
group by a
order by count(b) desc


I am using HSQLDB, and when i try this query at their gui it does work.
From the code using hibernate i get:
QuerySyntaxException: unexpected token

Seems when i even try to simplify the inner query it still does not work.
(I tried ... from ( select * from T) ... same error)

Any ideas?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 7:10 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
bump


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 8:12 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Post some java code if possible. Sorry if I have misunderstood but it looks like you have confused SQL with HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 8:20 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
my code is:
Code:
public List<Object[]> getHistogram(Long limit)
    {       
        return (List<Object[]>) session.createQuery
                ("select type, count(name)" +
                 " from " + (select" + (limit == null ? "" : " limit 0 " + limit) + " *" +                 
                 " from " + PLAYER_TABLE_NAME +
                 " order by acres desc" + ")" +
                 " group by type" +
                 " order by count(name) desc").list();
    }


What i am doing is: returning number of players per each type.
But i want to query only for example 'limit' of top players, not all of them....
(so i ordered them)

I run this query directly in hsqldb gui and it works.
Doesnt work in the java code with hibernate for me.
The sql is fine


Last edited by Archmisha on Fri Feb 01, 2008 9:06 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 8:25 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
http://www.hibernate.org/hib_docs/reference/en/html/queryhql.html


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 8:42 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
Thanks for your link, i did read this section
If you could pinpoint me to the problem i would be greatfull

I cant find there any reference on how to make nested query.
As i understand join wont help me in this case.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 9:12 am 
Regular
Regular

Joined: Mon Aug 20, 2007 6:47 am
Posts: 74
Location: UK
Archmisha wrote:
Thanks for your link, i did read this section
If you could pinpoint me to the problem i would be greatfull

I cant find there any reference on how to make nested query.
As i understand join wont help me in this case.


You are trying to query hibernate using SQL, when you need to use HQL.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 01, 2008 10:10 am 
Beginner
Beginner

Joined: Thu Aug 09, 2007 3:48 pm
Posts: 38
Thank you very much.
I do understand now my mistake.

But i still unable to understand how to form the hql query i need.
If any1 could help me with that please.


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