Uploaded image for project: 'Hibernate ORM'
  1. HHH-13095

Document how to use arithmetic expressions in CASE statements

    Details

    • Type: Task
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: 5.3.7
    • Fix Version/s: 5.4.0
    • Component/s: documentation
    • Labels:
      None
    • Last commented by a user?:
      true
    • Sprint:

      Description

      When writing an HQL query like this one:

      select case when p.name = 'Steve' then p.id * 10 else p.id end from Person p order by p.id
      

      We get the following exception thrown:

      Caused by: org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: * near line 1, column 45 [select case when p.name = 'Steve' then p.id * 10 else p.id end from org.hibernate.test.hql.CaseStatementTest$Person p order by p.id]
      	at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:74)
      	at org.hibernate.hql.internal.ast.ErrorTracker.throwQueryException(ErrorTracker.java:93)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.parse(QueryTranslatorImpl.java:297)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:189)
      	at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:144)
      	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:118)
      	at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:78)
      	at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:158)
      	at org.hibernate.internal.AbstractSharedSessionContract.getQueryPlan(AbstractSharedSessionContract.java:595)
      	at org.hibernate.internal.AbstractSharedSessionContract.createQuery(AbstractSharedSessionContract.java:704)
      

      The problem is caused by the * operator in this example.

        Attachments

          Activity

            People

            • Assignee:
              mih_vlad Vlad Mihalcea
              Reporter:
              mih_vlad Vlad Mihalcea
              Participants:
            • Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: