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
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
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/
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.
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.