Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

JPA Exceptions for certain case constructs #185

Closed
timowest opened this issue Jun 29, 2012 · 4 comments
Closed

JPA Exceptions for certain case constructs #185

timowest opened this issue Jun 29, 2012 · 4 comments
Labels
Milestone

Comments

@timowest
Copy link
Member

@timowest timowest commented Jun 29, 2012

query().from(cat).list(cat.name.when("Bob").then(1).otherwise(2));

throws the following exception when executed with Hibernate

java.lang.ClassCastException: org.hibernate.hql.ast.tree.ParameterNode cannot be cast to org.hibernate.hql.ast.tree.SelectExpression
at org.hibernate.hql.ast.tree.CaseNode.getFirstThenNode(CaseNode.java:44)
at org.hibernate.hql.ast.tree.CaseNode.getDataType(CaseNode.java:40)
at org.hibernate.hql.ast.tree.SelectClause.initializeExplicitSelectClause(SelectClause.java:154)
at org.hibernate.hql.ast.HqlSqlWalker.useSelectClause(HqlSqlWalker.java:857)
at org.hibernate.hql.ast.HqlSqlWalker.processQuery(HqlSqlWalker.java:645)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.query(HqlSqlBaseWalker.java:685)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.selectStatement(HqlSqlBaseWalker.java:301)
at org.hibernate.hql.antlr.HqlSqlBaseWalker.statement(HqlSqlBaseWalker.java:244)
at org.hibernate.hql.ast.QueryTranslatorImpl.analyze(QueryTranslatorImpl.java:256)
...

@timowest
Copy link
Member Author

@timowest timowest commented Jun 29, 2012

timowest added a commit that referenced this issue Aug 5, 2013
@nithril
Copy link
Contributor

@nithril nithril commented Jan 13, 2014

This construct works as expected

query().from(cat).list(cat.name.when("Bob").then(Expressions.numberTemplate(Long, "1")).otherwise(Expressions.numberTemplate(Long, "2")));

I haven't digg for an explanation

@sebdotv
Copy link

@sebdotv sebdotv commented Nov 17, 2014

solution suggested by @nithril also allows to workaround Hibernate bug https://hibernate.atlassian.net/browse/HHH-9343 (Could not determine data type for searched case statement) where QueryDSL would otherwise use parameters even for number literals

@timowest
Copy link
Member Author

@timowest timowest commented Nov 30, 2014

Released in 3.6.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

3 participants
You can’t perform that action at this time.