1

How to select last inserted 5 record from table using JPA with Hibernate?

public List<Sample> getAgencyChangeLastFiveRecords(){
    return (ArrayList<Sample>) createQuery(
        "select * from ( select * from sample order by id desc) where rownum<=5 order by rownum desc"
    );
}

This is not working. What would be the corresponding HQL query?

Jonathan
  • 20,053
  • 6
  • 63
  • 70
nag
  • 647
  • 6
  • 25
  • 43

1 Answers1

0

may be you can try below

 String hql="from Sample order by id desc"
 Query.setMaxResults(5)
Jigar Parekh
  • 6,163
  • 7
  • 44
  • 64