Custom order by string parameter in HQL
Use a criteria query.
List<User> users = session.createCriteria(User.class)
.add(Restrictions.isNotNull("joined"))
.addOrder(Order.desc(order))
.list();
Or, using HQL:
Query query = session.createQuery("from User as user where user.joined!=null order by user." + order + " desc");