[hibernate-issues] [Hibernate-JIRA] Commented: (HHH-2381) Criteria API : Order by Native SQL

Taro App (JIRA) noreply at atlassian.com
Thu Mar 12 03:11:39 EDT 2009


    [ http://opensource.atlassian.com/projects/hibernate/browse/HHH-2381?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=32634#action_32634 ] 

Taro App commented on HHH-2381:
-------------------------------

I have another use case in which this functionality would be very useful.

I have Product entity, which is stored in Second Level Cache because product data is needed frequently.
I also have product query form. The result can be sorted by several options such as by item name, by sales, etc.

To sort by item name, it is as easy as this: criteria.addOrder(Order.asc('itemName'))

Sortint by sales is not as easy. Derived property is not a good solution here, because I don't want sales to be cached.
It would be as easy as this if native sql order by is supported:
criteria.addOrder(NativeSQLOrder.asc("select sum(o.sales) from orders o where o.item_id = item_id"));

I also have more cases which needs native sql order by functionality:
- Sorting Product by number of Bids places for that Product.
- Sorting Product by ProductCategory display order in which needs Oracle Hierarchy Query


> Criteria API : Order by Native SQL 
> -----------------------------------
>
>                 Key: HHH-2381
>                 URL: http://opensource.atlassian.com/projects/hibernate/browse/HHH-2381
>             Project: Hibernate Core
>          Issue Type: Improvement
>          Components: query-criteria
>            Reporter: Sami Dalouche
>
> 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

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: http://opensource.atlassian.com/projects/hibernate/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        



More information about the hibernate-issues mailing list