I wanted to fetch the last 5 records of an entity. But unable to fetch it via Spring Data JPA.
Initially I was trying to get the data via LIMIT query but LIMIT isn't supported in JPA.
Later I tried with Pageable
interface.
Pageable pageCount = new PageRequest(0, 10, Direction.ASC,"id");
List<TxnEntity> txnEntities = txnDAO
.findByAccountEntity(accountEntity,pageCount);
This gives me first page with 10 Objects.
But my requirement is to get last 10 or 5 Objects. So how can I get it via Pageable
interface in the Spring framework?
You could reverse your sort and then get the first 5.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With