Reputation: 1506
Is there a way to use the SQL 'ORDER BY LENGTH` in JPA (Spring)? We're trying to eliminate the usage of native queries.
Here is the native query:
SELECT * FROM table WHERE columnOne ORDER BY LENGTH(columnTwo) DESC LIMIT 1
Thank you!
Upvotes: 1
Views: 547
Reputation: 1078
To call functions in JPQL you use:
function(funtion_name, arg_1, arg_2, arg_n)
So your query would become:
select t from table t where t.columnOne order by function('length', t.columnTwo) desc
With JPQL you can't use limit in the query so you could use Pagination.
Upvotes: 2