How to bind specification with queries

Viewed 65

I'm trying to annotate a custom query with specifications. I have around 9 APIs with the same specification and I don't want to create 9 annotated queries. the problem here is each API is filtering depending on a different column but all APIs have the same specifications.

Is that possible without using the find-all method? here is what I tried.

public interface DoctorSpecialityRepository extends JpaRepository<DoctorSpecialityEntity, Integer>, JpaSpecificationExecutor<DoctorSpecialitySpecification> {

     ArrayList<DoctorSpecialityEntity> getDoctorsWithFilter(@Param("subSpecialities") ArrayList<SpecialitiesCountriesEntity> subSpecialities, DoctorSpecialitySpecification specification);

but it throws an exception

Using named parameters for method public abstract java.util.ArrayList com.plus.doctors.repositories.DoctorSpecialityRepository.getDoctorsWithFilter
1 Answers

You don't need to declare methods in your jpaRepository, you can directly write your custom queries in specification class.you can build an extensible set of predicates on top of an entity that then can be combined and used with JpaRepository without the need to declare a query (method) for every needed combination.

Related