How do I sort list with criteria in hibernate

后端 未结 2 662
被撕碎了的回忆
被撕碎了的回忆 2021-02-05 12:13

I am new to Spring3 and Hibernate the following code works great but I am trying to find a way to have my list returned in sort order by the date field. Can someone please show

2条回答
  •  逝去的感伤
    2021-02-05 12:52

    Either have the database do it or Java, your choice. Here's how to do it in Java:

    List friends = sessionFactory.getCurrentSession()
           .createCriteria(Friend.class)
            .add(Example.create(friend))
            .list();
    Collections.sort(friends); 
    
    return friends;
    

提交回复
热议问题