For example, with Hibernate, you can use the LOWER function for p.name in ORDER BY:
select p from Plan as p where p.location = :location order by LOWER(p.name)
I assume that the above is not guaranteed to work with all JPA implementations, because the ORDER BY argument is not one of the following:
- A state_field_path_ expression that evaluates an ordered state field of an object or a nested type of an abstract class scheme specified in a SELECT clause by one of the following:
• general_identification_variable
• single_valued_object_path_expression - A state_field_path_ expression that evaluates to a single state field of the same object or a nested abstract schema type as the state_field_path_ expression in a SELECT expression
- Result_variable, which refers to an ordered element in a SELECT clause for which the result_variable parameter is specified. This may be the result of an aggregate_expression, a scalar_expression, or state_field_path_expression expression in a SELECT clause. For example, the four requests below are legal.
If it does not work with your JPA implementation, you should use the following query:
select p, LOWER(p.name) AS name_order from Plan as p where p.location = :location order by name_order
The disadvantage is that the query result is a list of arrays of objects, the first element in each list is an instance of the Plan object and the second element to be discarded.
source share