我需要根据sort field
检索对象的排序列表;它们的集合类型为SortedSet
,但代码抛出异常。
我还尝试添加@Sort
注释,如hibernate documentation的排序集合部分所述,但它似乎已被弃用!
例外
Caused by: org.hibernate.AnnotationException: A sorted collection must define and ordering or sorting
代码
SortedSet<Offer> offers = new TreeSet<Offer>();
类
public class Person {
@Id
long id;
@OneToMany
//@OrderBy("sort ASC") <<< If I use this just one offer will be in the collection
SortedSet<Offer> offers = new TreeSet<Offer>();
...
}
public class Offer implements Comparable<Offer>{
@Id
long id;
String name;
short sort;
@Override
public int compareTo(Offer o) {
return sort - o.sort;
}
}
答案 0 :(得分:13)
您需要指定要放在ORDER BY子句中的列名
尝试将此注释添加到SortedSet
@javax.persistence.OrderBy("sort")