0

I'm trying to get the list of only the last five rows from the table. I've already tried with limit 5 but no luck .

Here is the method

@Transactional
public List<Poll> findAllLimit5() {
    return em.createQuery("select a from Poll a ", Poll.class).getResultList();
}

Any help is much appreciated.

B. Adly
  • 37
  • 1
  • 6

1 Answers1

0

Here is the modified method

@Transactional
public List<Poll> findAllLimit5() {
    return em
            .createQuery("select a from Poll a ORDER BY a.id_poll DESC ",
                    Poll.class).setMaxResults(5).getResultList();

}
B. Adly
  • 37
  • 1
  • 6