What is the best way to query an Object and return its list attributes in a sorted list?
Example:
Given the scenario below, what is the best way to do a Groups query, by bringing: the list of Items ordered by name and (for each item) the list of StateItem ordered by the Description of StateObject?
public class Group {
// ...
@Fetch(FetchMode.JOIN)
@OneToMany(mappedBy = "group")
private List<ItemGroup> itemList;
// ...
}
public class ItemGroup {
// ...
@JoinColumn(name="ID_GROUP", referencedColumnName="ID_GROUP")
@ManyToOne
private Group group;
@Fetch(FetchMode.JOIN)
@OneToMany(mappedBy = "item")
private List<StateItem> stateList;
// ...
}
public class StateItem {
// ...
@JoinColumn(name="ID_ITEM", referencedColumnName="ID_ITEM")
@ManyToOne
private ItemGroup item;
@JoinColumn(name="CD_STATE", referencedColumnName="CD_STATE")
@ManyToOne
private StateObject state;
// ...
}
public class StateObject {
// ...
@Column(name="DE_STATE_OBJECT", length=255)
private String description;
// ...
}
PS: I think I can't use @OrderBy because I have to sort by child attributes, as in the StateObject example. And the solution with @SortNatural or @SortComparator isn't performatic. Can I do that work using only HQL or Criteria?