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
  • 19,557
  • 6
  • 64
  • 67
nag
  • 637
  • 6
  • 24
  • 43

1 Answers1

0

may be you can try below

 String hql="from Sample order by id desc"
 Query.setMaxResults(5)
Jigar Parekh
  • 5,955
  • 5
  • 42
  • 64