Custom finder method not working at spring data jpa

Viewed 50

My idea was to create a custom finder method to search employee reimbursements cases based on employee id. Therefore, I was creating a Custom finder method called findByReimbursementApplicantID.

The SQL query should be SELECT * FROM reimbursements WHERE reimbursementApplicantID = ? But it wasn't working. Any idea will be much appreciated it.

At Entity

[@Entity
@Table(name = "reimbursement")
public class ReimbursementEntity {
@Column(name = "reimbursement_applicant_id")
private int reimbursementApplicantID;][1]

At Repository

    @Repository("reimbursementRepository")
        public interface ReimbursementRepository extends JpaRepository<ReimbursementEntity, Integer> {
        
        public List<Reimbursement> findByReimbursementApplicantID(int reimbursementApplicantID);
}

At services @Override

public List<Reimbursement> searchReimbursements(int reimbursementApplicantID)  {
        List<Reimbursement> allReimbursementEntity = reimbursementRepo.findByReimbursementApplicantID(reimbursementApplicantID);
        List<Reimbursement> allReimbursement = new ArrayList<Reimbursement>();
        for (Reimbursement reimbursementEntity: allReimbursementEntity) {
            Reimbursement reimbursement = new Reimbursement(reimbursementEntity.getReimbursementApplicantID(),
                    reimbursementEntity.getReimbursementAmount() , 
                    reimbursementEntity.getReimbursementSubmitTime() ,
                    reimbursementEntity.getReimbursementDescription(), 
                    reimbursementEntity.getReimbursementResolvedTime(),
                    reimbursementEntity.getReimbursementApplicantID() , 
                    reimbursementEntity.getReimbursementStatusID());
                    allReimbursement.add(reimbursement);
        }
        return allReimbursement;
        }
0 Answers
Related