-->
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.  [ 1 post ] 
Author Message
 Post subject: How should I declare my method to support dynamic sorting?
PostPosted: Fri May 12, 2006 12:22 pm 
Regular
Regular

Joined: Wed Apr 12, 2006 12:49 am
Posts: 105
Location: Malaysia
Need help with Hibernate? Read this first:
http://www.hibernate.org/ForumMailingli ... AskForHelp

Hibernate version:
3.1.3

Below is one of the example that I saw that passes 2 objects (user and item) to do a query. I would like to get some advice on how can we enhance this findUsers method to take in dynamic sort criteria so that it is reusable for different cases. For example, sometimes we might want to sort by user name, sometimes maybe by item id, sometimes by multiple fields. So, would like to know what's the better way to declare the parameter to support dynamic sort.

Code:
public List findUsers(User u, Item i) throws HibernateException {
Example exampleUser =
Example.create(u).ignoreCase().enableLike(MatchMode.ANYWHERE);
Example exampleItem =
Example.create(i).ignoreCase().enableLike(MatchMode.ANYWHERE);
return getSession().createCriteria(User.class)
.add( exampleUser )
.createCriteria("items")
.add( exampleItem )
.list();
}


Thanks.


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

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.