J.P
J.P

Reputation: 141

Reversed sorting in Spring Data JPA

How i can sort entites from the end of table? I usualy used reversed comparator. I try this,but is not work in spring data jpa:

 @Transactional(readOnly=true)
public List<Terapija> top10TerapijePacijenta(String jmbg){
   List<Terapija> ter= terapijaRepository.findByJmbgPacijeta(jmbg);
   Comparator<Terapija> comp = comp.reversed();

  return  ter.sort(comp);

Upvotes: 0

Views: 936

Answers (1)

sidgate
sidgate

Reputation: 15234

Define new method in the Repository that will specify the ordering. Assuming you want the first created rows on the top, order the result by ID in ascending order

List<Terapija> terapijaRepository.findByJmbgPacijetaOrderByIdAsc();

Upvotes: 1

Related Questions