Yes there is a way using the formula annotation. The annotation would be placed on the Foo class. Note that the formula annotation accepts sql column names and not object property names.
@Formula("col1+col2+col3")
private int calculatedValue;
public int getCalculatedValue() {
return calculatedValue;
}
public void setCalculatedValue(int calculatedValue) {
this.calculatedValue = calculatedValue;
}
The detached query would look like something below.
DetachedCriteria query = DetachedCriteria.forClass(Foo.class);
query.addOrder(Order.desc("calculatedValue"));
List<Foo> results = query.getExecutableCriteria(session).setMaxResults(100).list();