我在实体中有一个 SortedSet。但是当我尝试获取它时,它并没有排序。我尝试使用hibernate或jpa,都不起作用。任何原因?(我的设置实体也实现了可比性)
private SortedSet<News> news = new TreeSet<News>();
public void setNews(SortedSet<News> news) {
this.news = news;
}
@OneToMany(fetch = FetchType.EAGER, cascade = {CascadeType.PERSIST, CascadeType.MERGE })
@JoinTable(name = "NEWSGROUP_NEWS", joinColumns = @JoinColumn(name = "NEWSGROUP_ID"), inverseJoinColumns = @JoinColumn(name = "NEWS_ID"))
@OrderBy("title")
@Sort(type=SortType.COMPARATOR, comparator=NewsComparator.class)
public SortedSet<News> getNews() {
return this.news;
}
public static class NewsComparator implements Comparator<News>
{
@Override
public int compare(News news1, News news2) {
return news1.getTitle().compareTo(news2.getTitle());
}
}
我的道
NewsGroup newsGroup = (NewsGroup)this.hibernateSessionFactory.getCurrentSession().get(NewsGroup.class, id);
我还打印了 sql(打开了 show_sql),但它根本没有显示 order by。请指教。谢谢!