The problem I am having is that I have a class A that has a Set of class B (Needs to be a Set, not a List). I need the Set of class B to always be loaded ordered by B.name ascending. I have the following annotations in class A to accomplish this:
Code:
Class A{
@OneToMany(mappedBy="itemA", fetch=FetchType.EAGER)
@OrderBy("name")
private Set<B> itemBs = new HashSet<B>();
...
}
However, when I perform a search for A's in the database, I need my list of results to come back ordered by A.name. Instead they are coming back ordered by B.name and then A.name. My search method looks like this:
Code:
private Criteria buildSearchCriteria(SearchCommand command)
{
Criteria crit = getSession().createCriteria(A.class);
....//Build search parameters, add restrictions to criteria
crit = crit.addOrder(Order.asc("name").ignoreCase());
return crit;
}
I am wondering if there is a way to tell Hibernate to apply the Criteria Order By clause before the Annotation Order By clause?
Or any other suggestions would be much appreciated.
Thanks! :)