-->
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: select case when then else end problem
PostPosted: Tue May 10, 2005 7:22 am 
Beginner
Beginner

Joined: Wed Feb 16, 2005 1:22 am
Posts: 25
Location: Jakarta
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.0.3

Mapping documents:

Code between sessionFactory.openSession() and session.close():

Full stack trace of any exception that occurs:
Exception in thread "main" java.lang.IllegalStateException: Unexpected AST: org.hibernate.hql.ast.SqlNode
+-[CASE] SqlNode: 'case'
| +-[WHEN] SqlNode: 'when'
| | +-[EQ] SqlNode: '='
| | | +-[DOT] DotNode: 'mstchartof0_.CHART_OF_ACC_TYPE' {propertyName=chartOfAccType,dereferenceType=4,propertyPath=chartOfAccType,path=A.chartOfAccType,tableAlias=mstchartof0_,className=distr.mst.model.MstChartOfAccount,classAlias=A}
| | | | +-[ALIAS_REF] IdentNode: 'mstchartof0_.CHART_OF_ACC_CODE' {alias=A, className=distr.mst.model.MstChartOfAccount, tableAlias=mstchartof0_}
| | | | \-[IDENT] IdentNode: 'chartOfAccType' {originalText=chartOfAccType}
| | | \-[QUOTED_STRING] LiteralNode: ''D''
| | \-[QUOTED_STRING] LiteralNode: ''Debet''
| \-[ELSE] SqlNode: 'else'
| \-[QUOTED_STRING] LiteralNode: ''Kredit''

at org.hibernate.hql.ast.SelectExpressionList.collectSelectExpressions(SelectExpressionList.java:31)
at org.hibernate.hql.ast.SelectClause.initializeExplicitSelectClause(SelectClause.java:123)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:440)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:351)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.afterQuery(HqlSqlBaseWalker.java:126)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:471)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:201)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:151)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:189)
at org.hibernate.hql.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:130)
at org.hibernate.hql.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:83)
at org.hibernate.impl.SessionFactoryImpl.getQuery(SessionFactoryImpl.java:425)
at org.hibernate.impl.SessionImpl.getQueries(SessionImpl.java:880)
at org.hibernate.impl.SessionImpl.list(SessionImpl.java:830)
at org.hibernate.impl.QueryImpl.list(QueryImpl.java:74)
at test.HibernateQueryTester.main(HibernateQueryTester.java:63)


Name and version of the database you are using:
Oracle 9.2.0.1

The generated SQL (show_sql=true):

Debug level Hibernate log excerpt:

Hi guys,
I'm experiencing an error while trying the select case .. when .. then .. else .. end.
This is the HQL :

List list = session.createQuery(
"select " +
"A.chartOfAccCode, A.chartOfAccName, " +
"case " + //case when ... then ... else ... end
"when A.chartOfAccType = 'D' " +
"then 'Debet' " +
"else 'Kredit' " +
"end " + ", " +
"A.chartOfAccGroup, A.subLedgerExistFlag, A.subAccBranchFlag, A.subAccBureauFlag, A.subAccSectorFlag, " +
"A.activeFlag " +
"FROM MstChartOfAccount A")
.list();


And the exception trace is above ...
Please help meee
^-^
Thanks,
Albert Kam


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 8:11 am 
Beginner
Beginner

Joined: Thu Apr 21, 2005 5:37 am
Posts: 45
Location: Switzerland
Are you shure that the "case when ... then ... else ... end "-Stuff exists in HQL? It may exist in (Oracle-)SQL, but in HQL? See also http://www.hibernate.org/hib_docs/reference/en/html_single/


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 10, 2005 9:04 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
case is supported in the where clause, but not in the select clause in HB3.

It's probably pretty easy to add support, please feel free to submit a feature request to JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Wed May 11, 2005 1:05 am 
Beginner
Beginner

Joined: Wed Feb 16, 2005 1:22 am
Posts: 25
Location: Jakarta
Thanks alot for the responses.

I've already submitted the request to JIRA. Hope i did it right, havent tried JIRA before =p.

Really hope getting this to become a feature of hibernate. Thank you very very much !

Sincerely,
Albert Kam


Top
 Profile  
 
 Post subject: workaround for hibernate 2
PostPosted: Tue Jul 05, 2005 12:01 pm 
Newbie

Joined: Tue Jul 05, 2005 11:59 am
Posts: 1
Is there any suggested strategies for doing this in Hibernate 2?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 3:41 am 
Newbie

Joined: Thu Aug 16, 2007 3:02 am
Posts: 12
Location: Banglore
Hi,
case when is working for me in select clause.
please try after removing the '=' symbol in when

List list = session.createQuery(
"select " +
"A.chartOfAccCode, A.chartOfAccName, " +
"case " + //case when ... then ... else ... end
"when A.chartOfAccType 'D' " +
"then 'Debet' " +
"else 'Kredit' " +
"end " + ", " +
"A.chartOfAccGroup, A.subLedgerExistFlag, A.subAccBranchFlag, A.subAccBureauFlag, A.subAccSectorFlag, " +
"A.activeFlag " +
"FROM MstChartOfAccount A")
.list();

_________________
sirajulmuneer


Top
 Profile  
 
 Post subject: Re: select case when then else end problem
PostPosted: Thu Nov 19, 2009 7:09 am 
Newbie

Joined: Wed Nov 18, 2009 5:31 pm
Posts: 2
I was looking for a similar "case when then end". Thanks for the help.


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.