HQL Parser does not recognize columns after a case expression in a constructor expression


When I create an HQL query with a case expression inside a constructor expression, Hibernate seems to stop at the end of the case expression, ignoring the other parameters of the constructor expression. For example, if there is a class called Node, with the following constructor:

Node(long, String, boolean, boolean, boolean)

The following query works on EclipseLink, but not on Hibernate:
select new Node(p.id, p.name, case when (select 1 from Product p2 where p2.fullPath like concat(p.fullPath, '%') and p2 <> p), false, true) from Product p

Hibernate generates an error saying that it couldn't find a constructor with the form Node(long, String, boolean), i.e., it ignores the other two parameters.

set 22, 2014 2:15:52 PM org.hibernate.hql.internal.ast.ErrorCounter reportError
ERROR: Unable to locate appropriate constructor on class [app.Node]. Expected arguments are: long, java.lang.String, boolean
[cause=org.hibernate.PropertyNotFoundException: no appropriate constructor in class: app.Node]

I've read the JPQL grammar, and it allows expressions of that form, and since it works too in EclipseLink, I guess it may be a bug in Hibernate.

I discovered the error on our Java EE app, and I've attached a Java SE test case that can reproduce the problem. The test case is a Maven project and it is ready to connect to a PostgreSQL database called hql_test, running in localhost and with user/pass postgres/postgres.


Hibernate 4.3.6, Java SE 8, Java EE 7 / Wildfly 8.1


Gabriel Morrison Lima Dantas
September 22, 2014, 5:55 PM

Just an update: there is a "= 1" missing after the case end in the example query above and in the query inside the Main class in the test project. I uploaded the correct test case project (hql-test-fixed.zip) and the query above becomes:

select new Node(p.id, p.name, case when (select 1 from Product p2 where p2.fullPath like concat(p.fullPath, '%') and p2 <> p) = 1 then true else false end, false, true) from Product p

Steve Ebersole
October 27, 2015, 7:16 PM

This bug report does not indicate that the reported issue affects version 5.x. Versions prior to 5.x are no longer maintained. It would be a great help to the Hibernate team and community for someone to verify that the reported issue still affects version 5.x. If so, please add the 5.x version that you verified with to the list of affected-versions and attach the (preferably SSCCE) test case you used to do the verification to the report; from there the issues will be looked at during our triage meetings.

For details, see http://in.relation.to/2015/10/27/great-jira-cleanup-2015/

Steve Ebersole
October 28, 2015, 3:26 AM

As part of verifying that this issue affects 5.0, please just set the "Affects version". Leave the "verify-affects-5.0" label and leave the issue in "Awaiting Response" status; these are critical for us to be able to track these verifications and triage them. Thanks.

Gabriel Morrison Lima Dantas
November 16, 2015, 11:45 PM

The issue still affects Hibernate 5. I've noticed that the test case was with the '..' folder in it, so I uploaded one without it.




Gabriel Morrison Lima Dantas

Fix versions




Suitable for new contributors


Requires Release Note


Pull Request





Affects versions