Criteria API : Order by Native SQL

Description

Hi,

It would be nice to be able to specify the ORDER BY clause using Native SQL. (It is currently doable by subclassing the Order class, but some nice solution would allow the order to specify attributes on another table..)

Let's take a simple example : I have a distance("attribute", geometry) function, that is of course, proprietary.

I am quering table A, which I can join to table B to get the "attribute", on which I want to apply my distance() function.

If I create my own Order subclass, and addOrder on the criteria, the distance("attribute, geometry) is going to refer to the main criteria's class mapping.

So, something like addOrder("objectpath.joined", new MyOrder(...)); would be perfect.

What do you think ?
Regards,
Sami Dalouche

Attachments

2
  • 14 Mar 2013, 05:38 PM
  • 20 Aug 2010, 04:53 PM

Activity

Show:

Jan Schatteman November 24, 2023 at 8:40 PM

This issue has been rejected since the Hibernate legacy Criteria API was deprecated in 5.x and removed in 6.0. There will be no further development for it.

Ondrej Medek March 14, 2013 at 5:38 PM
Edited

I have improved the NativeSQLOrder for raw really SQL ordering.

Ondrej Medek March 14, 2013 at 5:36 PM
Edited

@Rico: you do not need this, just subclass the Order class, as the NativeSQLOrder class does.

June 28, 2011 at 3:05 PM

Is it possible to refactor Order to simplify writing db specific Order class (typically for NLS_SORT in Oracle)? For instance, by changing the visibility of fields ascending, ignoreCase & propertyName (protected instead of private) ;

Ondrej Medek August 20, 2010 at 4:53 PM

Hi, thanks for your NativeSQLOrder. I have improved it for alias substiution. Now you can write something like NativeSQLOrder.asc("{person.name}||' '||{person.surname}");

Out of Date

Details

Assignee

Reporter

Labels

Components

Priority

Created January 25, 2007 at 12:16 AM
Updated November 24, 2023 at 8:40 PM
Resolved November 24, 2023 at 8:40 PM