Is it possible to use both @Query
annotation and specification in one repository method? For example I'd like to have a method like this:
@Query(value="SELECT e from EMPLOYEE where firstName <> ?1")
public Page<Employee> findEmployeeBySomethigFancy(String firstName, Pageable pageable, Specification<Employee> emp);
Is it possible or should I build the whole query as a Predicate
and remove the @Query
annotation?
First you might want to read this blog post first. Second, according to the JpaSpecificationExecutor interface that your repositories should implement you can run the following queries using Specifications:
So you need can't mix @Query (or query-methods) and Specifications.
You can express this condition:
using a Specification instead. Then you can combine as many specifications as you want.