I have a table USERS with names and creation dates, and an api function
T read(Criterion... criteria)
that searches by criterions that i cant change.
My problem is that the function returns crit.uniqueResult() but sometimes the criteria gives many names (in which case i want only the name with the latest date).
how can i add a criterion to make sure only the latest name is returned?
public T read(Criterion... criteria){
Criteria crit = getSession(false).createCriteria(this.type);
for (Criterion c : criteria)
{
crit.add(c);
}
T entity = (T)crit.uniqueResult();
return entity;
}
Maybe you can have a read method that returned the top result, a method that returns a
List<T>and one that you pass in the number of results to return.For example you could use then use max results setting
http://docs.jboss.org/hibernate/core/3.2/api/org/hibernate/Criteria.html#setMaxResults%28int%29