0

I have a SortedSet within an entity. But when I try to fetch it doesn't sort. I tried to use hibernate or jpa, both not working. Any reason? (My set entity has implemented comparable too)

    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());

        }

    }

My Dao

NewsGroup newsGroup = (NewsGroup)this.hibernateSessionFactory.getCurrentSession().get(NewsGroup.class, id);

I have also printed the sql (with show_sql on) but it doesn't show order by at all. Please advise. Thanks!

Roy Chan
  • 2,888
  • 6
  • 36
  • 43

1 Answers1

0

JMelnik is right, by removing the @Sort, it worked

Roy Chan
  • 2,888
  • 6
  • 36
  • 43