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.