Query Parameters in Order clause

Description

The issue is already described on stackoverflow: http://stackoverflow.com/questions/41279113/java-hibernate-bug-when-using-query-parameters-in-order-clause

It is reproduceable with following tables and mappings. No classes required due to hibernate's non-pojo mode. Further note that this issue happens also, when using JPA criteria API and adding an order clause, because Hibernate resolves literals as named parameters.

— SQL
CREATE TABLE "APERSON"
(
"ID" VARCHAR2(50) PRIMARY KEY NOT NULL,
"NAME" VARCHAR2(255)
);
CREATE TABLE "AADDRESS"
(
"ID" VARCHAR2(50) PRIMARY KEY NOT NULL,
"PERSON" VARCHAR2(50) NOT NULL, – foreign key
"NAME" VARCHAR2(255)
);
INSERT INTO "APERSON" (ID, NAME) VALUES ('1', 'me');
INSERT INTO "APERSON" (ID, NAME) VALUES ('2', 'you');

— hbm file
<class entity-name="Person" table="APERSON">
<id name="id" column="ID" type="string" />
<property name="name" column="NAME" type="string" />
<bag name="address" fetch="subselect" lazy="false" inverse="true">
<key column="PERSON" />
<one-to-many entity-name="Address" />
</bag>
</class>

<class entity-name="Address" table="AADDRESS">
<id name="id" column="ID" type="string" />
<property name="name" column="NAME" type="string" />
</class>

— java code
em.createQuery("SELECT p FROM Person p ORDER BY concat(refix, p.name)").setParameter("prefix", "any").getResultList();

Environment

Hibernate 5.0.10, WildFly 10.1, Oracle 12.

Assignee

Unassigned

Reporter

Rafael Jonach

Fix versions

None

Labels

None

backPortable

None

Suitable for new contributors

None

Requires Release Note

None

Pull Request

None

backportDecision

None

Components

Affects versions

Priority

Major
Configure