Reputation: 141
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: 948
Reputation: 15254
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