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

"select new ..." with CAST( NULL AS ...) fails with QuerySyntaxException: unexpected AST node: NULL

    Details

    • Bug Testcase Reminder (view):

      Bug reports should generally be accompanied by a test case!

    • Last commented by a user?:
      true
    • Sprint:

      Description

      ... org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected AST node: NULL near line 1, column 59 [SELECT NEW support.hibernate.dto.EmployeeDTO(e.name, CAST(NULL as long), e.title) FROM support.hibernate.entity.Employee e WHERE e.name = :name]
              at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:54)
              at org.hibernate.hql.internal.ast.QuerySyntaxException.convert(QuerySyntaxException.java:47)
              at org.hibernate.hql.internal.ast.ErrorCounter.throwQueryException(ErrorCounter.java:79)
              at org.hibernate.hql.internal.ast.QueryTranslatorImpl.generate(QueryTranslatorImpl.java:240)
              at org.hibernate.hql.internal.ast.QueryTranslatorImpl.doCompile(QueryTranslatorImpl.java:205)
              at org.hibernate.hql.internal.ast.QueryTranslatorImpl.compile(QueryTranslatorImpl.java:138)
              at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:104)
              at org.hibernate.engine.query.spi.HQLQueryPlan.<init>(HQLQueryPlan.java:79)
              at org.hibernate.engine.query.spi.QueryPlanCache.getHQLQueryPlan(QueryPlanCache.java:168)
              at org.hibernate.internal.AbstractSessionImpl.getHQLQueryPlan(AbstractSessionImpl.java:222)
              at org.hibernate.internal.AbstractSessionImpl.createQuery(AbstractSessionImpl.java:200)
              at org.hibernate.internal.SessionImpl.createQuery(SessionImpl.java:1703)
              at org.hibernate.ejb.AbstractEntityManagerImpl.createQuery(AbstractEntityManagerImpl.java:301)
              ...
      

      Executing a query like the below

      final String hql = "SELECT NEW support.hibernate.dto.EmployeeDTO(e.name, CAST(NULL as long), e.title) FROM Employee e WHERE e.name = :name";
      

      Looks like something changed between Hibernate 4.2.7.SP5-redhat-1 (EAP 6.2.4) and Hibernate 4.2.14.SP1-redhat-1 (EAP 6.3.0) with regard to antlr parsing so that the keyword 'NULL' causes a parse failure in the HQL query. The issue remains in 5.0.9 and 5.1.0

      Replacing the 'CAST(NULL as long)' with 'CAST(12 as long)' works ...

      If the query in question is a @NamedQuery the failure will be at the point the entity manager is created. The same issue can be seen with a simple dynamic HQL query, however, as the testcase attached shows. The test uses an H2 db and can be run using 'mvn clean test'

        Attachments

          Issue links

            Activity

              People

              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: