there is two tables
* zine_subscribe_box Table
-----------------------------------------
column | Key
-----------------------------------------
user_id | PK
zine_id | PK, FK
issue_no | PK, FK
subscribe_date |
-----------------------------------------
| 1
| (one to many relation)
| n
-----------------------------------------
column | Key
-----------------------------------------
zine_id | PK, FK
issue_no | PK, FK
issued_date |
status |
-----------------------------------------
* zine_issue Table
zine_issue Table has relation one to n about zine_subscribe_box table
now I wan-na get the list by criteria like this.
--------------------------------------------------------------------
List list = session.createCriteria(ZineIssue.class)
.createCriteria("zineSubscribeBoxs")
.addOrder(Order.desc("subscribeDate"))
.list();
--------------------------------------------------------------------
'course this code throws exception "subcriteria cannot be ordered "
How do I get the order ZineIssue criteria by subscribeDate ?
I don't wan-na get ZineSubscribeBox criteria by subscribeDate....
Just I want get ZineIssue Classes....
Now I'm get the result reordering in the source like this.
--------------------------------------------------------------------
List list = session.createCriteria(ZineSubscribeBox.class)
.add(Expression.eq("comp_id.userId", "test"))
.createCriteria("zineIssue")
.add(Expression.eq("status", "C"))
.list();
List zines = new ArrayList();
for(int i=0; i < list.size(); i++) {
log.debug(((ZineSubscribeBox)list.get(i)).getSubscribeDate());
/* this re ordering result object */
zines.add(((ZineSubscribeBox)list.get(i)).getZineIssue());
}
for(int i=0; i < zines.size(); i++) {
log.debug(((ZineIssue)zines.get(i)).getIssuedDate());
Iterator iter =
((Set)((ZineIssue)zines.get(i)).getZineSubscribeBoxs()).iterator();
for (; iter.hasNext();) {
log.debug(((ZineSubscribeBox)iter.next()).getSubscribeDate());
}
}
--------------------------------------------------------------------
Is there anyone know get I ordered Object with ZineIssue more nicely ?
thanks your help
|