db-ojb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Vasily Ivanov (JIRA)" <j...@apache.org>
Subject [jira] Created: (OJB-104) Report sub-query in ORDER BY clause
Date Tue, 21 Mar 2006 22:30:05 GMT
Report sub-query in ORDER BY clause
-----------------------------------

         Key: OJB-104
         URL: http://issues.apache.org/jira/browse/OJB-104
     Project: OJB
        Type: Improvement
  Components: PB-API  
    Versions: 1.0.4, 1.0.3    
    Reporter: Vasily Ivanov
    Priority: Minor


There is no way in OJB to set report sub-query to ORDER BY clause.

QueryByCriteria.addOrderBy(String, boolean)
QueryByCriteria.addOrderBy(FieldHelper)
QueryByCriteria.addOrderByAscending(String)
QueryByCriteria.addOrderByDescending(String)

... no methods to set report sub-query.

Workaround:
I've got 2 classes:
class Parent:
 int id
 String data
 Collection children
class Child:
 int id
 String data
 int parentId
 Parent parent

I need to get collection of parents sorted by the number of children.
This is the code that works:
>QueryByCriteria query = QueryFactory.newQuery(Parent.class, new Criteria());
>query.addOrderByDescending("(SELECT count(1) FROM CHILD AAA WHERE
AAA.PARENT_ID = A0.ID)");
>persistenceManager.getBroker().getCollectionByQuery(query);

This is generated sql:
> SELECT A0.ID, A0.DATA, (SELECT count(1)
                                          FROM CHILD AAA
                                          WHERE AAA.PARENT_ID =
A0.ID) as ojb_col_3
> FROM PARENT A0
> ORDER BY 3 DESC

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


---------------------------------------------------------------------
To unsubscribe, e-mail: ojb-dev-unsubscribe@db.apache.org
For additional commands, e-mail: ojb-dev-help@db.apache.org


Mime
View raw message