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

Description

Executing a query like the below

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'

Environment

None

Activity

Show:
Gail Badner
May 27, 2016, 4:10 AM

A workaround is to replace null literals with nullif( 1, 1 ).

Gail Badner
May 27, 2016, 5:23 AM
Edited

In 4.2 branch, `git bisect` shows that it was broken by commit cfc0327637d80932782858705dd180010160dde5

In master branch, `git bisect` shows that it was broken by commit cbc79c2d61fc8c0d64dae90c61fe98990635c051 (in 4.3.6).

Gail Badner
June 1, 2016, 12:51 AM

Fixed in master, 5.1, and 5.0 branches.

Assignee

Gail Badner

Reporter

Stephen Fikes

Fix versions

Labels

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure