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(:prefix, p.name)").setParameter("prefix", "any").getResultList(); |