-->
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: from subquery in Hibernate
PostPosted: Tue Nov 10, 2009 11:09 am 
Newbie

Joined: Mon Aug 31, 2009 7:24 am
Posts: 7
Hi all,

I have a query with subselect and I found that Hibernate hasn't support for it.

Do you know how to correct (maybe after optimization:P) this query in HQL?

SELECT t1.greens, t2.oranges, t3.reds FROM
(SELECT count(t) as greens FROM tableX t WHERE t.validation="GREEN") t1,
(SELECT count(t) as oranges FROM tableX t WHERE t.validation="ORANGE") t2,
(SELECT count(t) as reds FROM tableX t WHERE t.validation="RED") t3

Table "tableX" is mapped correctly.


Top
 Profile  
 
 Post subject: Re: from subquery in Hibernate
PostPosted: Tue Nov 10, 2009 11:12 am 
Newbie

Joined: Mon Aug 31, 2009 7:24 am
Posts: 7
Sorry, I missed the following:

The exception raised by HQL parser is:

org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 1, column 23


Top
 Profile  
 
 Post subject: Re: from subquery in Hibernate
PostPosted: Wed Nov 11, 2009 9:08 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Hibernate Reference wrote:
Note that HQL subqueries can occur only in the select or where clauses.

_________________
-----------------
Need advanced help? http://www.viada.eu


Top
 Profile  
 
 Post subject: Re: from subquery in Hibernate
PostPosted: Thu Nov 12, 2009 12:26 pm 
Newbie

Joined: Mon Aug 31, 2009 7:24 am
Posts: 7
Hi mmerder,

thanks for your answer.

How could you re-write that query without using subselects?
I think that it's a quite common query to report counting on a table's column with different values.


Top
 Profile  
 
 Post subject: Re: from subquery in Hibernate
PostPosted: Mon Nov 23, 2009 5:11 am 
Expert
Expert

Joined: Thu Jan 08, 2009 6:16 am
Posts: 661
Location: Germany
Use native SQL or try to use a case-when.

_________________
-----------------
Need advanced help? http://www.viada.eu


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.