-->
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: query order by date desc
PostPosted: Thu Dec 06, 2007 5:08 am 
Newbie

Joined: Wed Sep 05, 2007 9:26 am
Posts: 16
Hi,
I have something like this:
public class Usr {
...
private List<MsgSubject> messageTopics = new ArrayList<MsgSubject>();
@OneToMany(mappedBy="usr")
public List<MsgSubject> getMessageTopics() {
return messageTopics;
}
...

I can retrieve the messageTopics using aUsr.getMessageTopics(), this returns a list as expected, now I'd like to get the messagesTopics according to a datefield in the object in a descending order, so that I can display only the last few entries in the table, any way to achieve this? thanks.
A.C.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 06, 2007 6:40 am 
Regular
Regular

Joined: Mon Jan 22, 2007 10:32 am
Posts: 101
Use something like

public class Usr {
...
private List<MsgSubject> messageTopics = new ArrayList<MsgSubject>();
@OneToMany(mappedBy="usr")
@OrderBy("datefield desc")
public List<MsgSubject> getMessageTopics() {
return messageTopics;
}

otherwise you can also use HQL query to order the objects in desired manner,

_________________
Please rate this post if you find it helpful


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.