[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [eclipselink-users] Best way to support case insensitive alphanumeric sorting..
|
I had a similar requirement and initially tried using the UPPER operator in the ORDER BY clause but that did not work for me. For example: "SELECT a.ID, a.name FROM Table a ORDER BY UPPER(a.name)"
What did work for me was specifying an upper-cased form of the column to sort on in the SELECT clause. For example: "SELECT a.ID, a.name, UPPER(a.name) AS name_order FROM Table a ORDER BY name_order"
-----Original Message-----
From: Tom Ware
Sent: Thursday, June 06, 2013 9:05 AM
To: eclipselink-users@xxxxxxxxxxx
Subject: Re: [eclipselink-users] Best way to support case insensitive alphanumeric sorting..
EclipseLink provides toUpperCase() and toLowerCase() expressions and JPA provides UPPER and LOWER operators. For queries I expect you could use those operators in the ORDER BY part of your query to sort.
If you are talking about a mapping, you could use an EclipseLink DescriptorCustomizer to add ordering by an EclipseLink expression to the selection query. Roughly:
OneToManyMapping oneToManyMapping =
(OneToOneMapping)descriptor.getMappingForAttributeName("attributeName");
ExpressionBuilder builder =
oneToManyMapping.getSelectionQuery().getExpressionBuilder();
Expression orderExpression = builder.get("postalCode").toLowerCase().ascending();
oneToManyMapping.getSelectionQuery().addOrdering(orderExpression);
-Tom
On 05/06/2013 11:54 AM, vaidya nathan wrote:
> Hi,
>
> What is the best way to support case insensitive alphanumeric sorting
> using jpa2 and eclipselink ? An example of what i would like to
> achieve is to sort on something similiar to the canada zips which could be alphanumeric..
>
> We are using Eclipselinks ReadAllQuery and Expression language to
> build our queries and the queries that we have so far is like this..
>
> SELECT * FROM
> (SELECT a.*, ROWNUM rnum FROM
> (SELECT DISTINCT t1.ID AS a1,<colname>
> FROM <Table> ORDER BY t0.<colname> ASC) a WHERE ROWNUM <= ?) WHERE rnum > ?
> )a
>
>
> Thx
>
>
>
>
> _______________________________________________
> eclipselink-users mailing list
> eclipselink-users@xxxxxxxxxxx
> https://dev.eclipse.org/mailman/listinfo/eclipselink-users
>
_______________________________________________
eclipselink-users mailing list
eclipselink-users@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/eclipselink-users