-->
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.  [ 1 post ] 
Author Message
 Post subject: Query in "Select Case when end " stmt
PostPosted: Tue Nov 01, 2005 12:51 pm 
Newbie

Joined: Wed Sep 28, 2005 1:05 am
Posts: 5
Hibernate version: 3.1

"Select case when then else end " statement works fine unless I add another query in the else clause.
Like below:

select p.category, CASE WHEN p.icrossingTaxonomy.icCategoryId is not null THEN 0
else (select count(*) from Products p1 where p.category = p1.category and p1.icrossingTaxonomy.icCategoryId is null )
end as number
from Products p where p.clients.feedId = 5
group by p.category, p.icrossingTaxonomy.icCategoryId

If I replace the query in the else clause by just a number, the query works fine. By adding that query I get the following exception:

org.hibernate.hql.ast.QuerySyntaxException: unexpected AST node: query [ select p.category, CASE WHEN p.icrossingTaxonomy.icCategoryId is not null THEN 0 else (select count(*) from com.icrossing.icfeedsR3.hibernate.mapping.Products p1 where p.category = p1.category and p1.icrossingTaxonomy.icCategoryId is null ) end as number from com.icrossing.icfeedsR3.hibernate.mapping.Products p where p.clients.feedId = 5 group by p.category, p.icrossingTaxonomy.icCategoryId ]
at org.hibernate.hql.ast.ErrorCounter.throwQueryException(ErrorCounter.java:59)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:221)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:154)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:101)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:473)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:1032)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:982)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at com.icrossing.icfeedsR3.model.category.LoadCategoriesModel.loadProductCategoriesSelect(LoadCategoriesModel.java:95)
at com.icrossing.icfeedsR3.model.category.LoadCategoriesModel.main(LoadCategoriesModel.java:123)
Caused by: <AST>:0:0: unexpected AST node: query
at org.hibernate.hql.antlr.HqlSqlBaseWalker.expr(HqlSqlBaseWalker.java:1298)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.caseExpr(HqlSqlBaseWalker.java:4633)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.arithmeticExpr(HqlSqlBaseWalker.java:2805)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExpr(HqlSqlBaseWalker.java:1990)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.aliasedSelectExpr(HqlSqlBaseWalker.java:2041)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectExprList(HqlSqlBaseWalker.java:1816)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectClause(HqlSqlBaseWalker.java:1380)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:541)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:269)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:217)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:214)
... 8 more


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.