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

Comments

Projects
None yet
3 participants
@timowest
Member

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

This comment has been minimized.

Show comment
Hide comment
Member

timowest commented Jun 29, 2012

timowest added a commit that referenced this issue Aug 5, 2013

@nithril

This comment has been minimized.

Show comment
Hide comment
@nithril

nithril Jan 13, 2014

Contributor

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

Contributor

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

This comment has been minimized.

Show comment
Hide comment
@sebdotv

sebdotv 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

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

This comment has been minimized.

Show comment
Hide comment
@timowest

timowest Nov 30, 2014

Member

Released in 3.6.0

Member

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