You are using JPQL, which does not support restricting results like this. When using native JPQL you should use setMaxResultsto limit the results.
Spring Data JPA, . , . find , .
findFirstByOrderById();
Pageable LIMIT.
@Query("SELECT s FROM Students s ORDER BY s.id DESC")
List<Students> getLastStudentDetails(Pageable pageable);
- ( ).
getLastStudentDetails(new PageRequest(0,1));
, SQL.