How do I sort list with criteria in hibernate

后端 未结 2 661
被撕碎了的回忆
被撕碎了的回忆 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<Friend> friends = sessionFactory.getCurrentSession()
           .createCriteria(Friend.class)
            .add(Example.create(friend))
            .list();
    Collections.sort(friends); 
    
    return friends;
    
    0 讨论(0)
  • 2021-02-05 12:57
    .addOrder( Order.desc("date") )
    

    Check the examples in the documentation

    0 讨论(0)
提交回复
热议问题