mrobi
mrobi

Reputation: 17

Using Springboot JpaRepository to get the last element stored in the database

 @Repository
public interface ThirdPartyRequestLogRepository extends JpaRepository<ThirdPartyRequestLog, Long>, JpaSpecificationExecutor<ThirdPartyRequestLog> {

    ThirdPartyRequestLog findTopByBusinessReferenceNumberOrderByIdDesc(String businessReferenceNumber);

} 

 ThirdPartyRequestLog creditApplicationLog = thirdPartyRequestLogRepository.findTopByBusinessReferenceNumberOrderByIdDesc(creditApplication.getBusinessReferenceNumber());

I want to get the last element by "business reference number" stored in the table but i'm getting a null. My method findTopByBusinessReferenceNumberOrderByIdDesc(creditApplication.getBusinessReferenceNumber() is returning null.

Upvotes: 0

Views: 575

Answers (1)

Aby Sebastin
Aby Sebastin

Reputation: 11

findTop1ByBusinessReferenceNumberOrderByIdDesc - Try this out.

Upvotes: 1

Related Questions