Quote:
In the UI, a sortable list shows a column named 'Name' that contains the businessName OR contactLastName + " " + contactFirstName if businessName is empty.
You have a number of options:
1. Add a property to your entity that is based on a Formula. In your case this formula would be (assuming a function NVL/similar exists in the database you use) - NVL(businessName, contactLastName || " " || contactFirstName). And then use this field in your Criteria
Code:
@Formula(value="NVL(businessName, contactLastName || ' ' || contactFirstName)")
String name
...
s.createCriteria(Client.class).addOrder(Property.forName("name").asc()).list()
Note: The formula is evaluated only when the entity is loaded but from what you say this approach should work out ok for you.
2. If you use a projection based result-set then you can have this formula added to the projection list.
Code:
Projection projection = Projections.sqlProjection("NVL(businessName, contactLastName || " " || contactFirstName) as name", new String[]{"name"}, new Type[]{Hibernate.STRING});
Projection projectionAlias = Projections.alias(projection, "name");
Criteria crit = s.createCriteria(Client.class)
.setProjection(Projections.projectionList()
.add(projectionAlias));
crit.addOrder(Order.asc("usr"));
3. Use HQL. Again use the formula in the projection list and order by that.
Code:
s.createQuery("select NVL(businessName, contactLastName || " " || contactFirstName) as name, …
from Client order by 1").list();
HTH.