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