-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: How can I order sub criteria ?
PostPosted: Mon Apr 04, 2005 3:13 am 
Newbie

Joined: Thu Mar 03, 2005 5:09 am
Posts: 7
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 04, 2005 3:34 pm 
Expert
Expert

Joined: Sat Jan 17, 2004 2:57 pm
Posts: 329
Location: In the basement in my underwear
Ordering is supported on Hib 3, I am assuming you are using Hibernate 2? If so, then you can't order on sub criteria I believe.

Other than that, why not just use a comparator rather than whatever it is you're trying to do in code.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.