'Postgres query to HQL: select t from TableName t where t.isActive=true order by t.extension->'desc'

Postgres query:

select t 
from TableName t 
where t.isActive=true 
order by t.extcol->'desc'

This work's fine.

Need help with HQL query which will do the same job.

String query = "select t from TableName t where t.isActive=true order by t.extcol->'desc'"
newList = TableNameModel.executeQuery(query);

Method threw 'java.lang.IllegalArgumentException' exception.

context: there is a table TableName where one column is extcol which contains object. Need to sort TableName based on a property desc which present in extcol json object.



Solution 1:[1]

For HQL you have the wrong syntax for sorting.

It should be order by t.extcol desc without the arrow and quotes.

see https://docs.jboss.org/hibernate/core/3.3/reference/en/html/queryhql.html#queryhql-ordering

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Onno Rouast