I want to implement Specifications
and want to use the findAll(Specification<T> spec)
method, but always when I insert an Specification Eclipse tells me:
The method findAll(Sort) in the type JpaRepository<Telefonbuch,Long> is not applicable for the arguments (Specification<Telefonbuch>)
I don't want to use Sort
. I hand over a specification so why does it always try to use the method with sort?
You can see here that the method is a suggestion by Eclipse: https://imgur.com/a/LuF6ZGK
Specification:
public interface Specification<T> {
Predicate toPredicate(Root<T> root, CriteriaQuery<?> query, CriteriaBuilder builder);
}
TelefonbuchSpecifications:
public static Specification<Telefonbuch> hasVorname(String vorname) {
return (root, query, cb) -> {
return cb.equal(root.get(Telefonbuch_.vorname), "%"+vorname.toLowerCase()+"%");
};
}
TelefonbuchRepository:
public interface TelefonbuchRepository extends JpaRepository<Telefonbuch, Long>, JpaSpecificationExecutor<Telefonbuch> {
SearchController:
public void search(String vorname, String nachname, String telefonnummer, String handynummer) {
if (!vorname.isEmpty()) {
List<Telefonbuch> list = telefonbuchRepository.findAll(TelefonbuchSpecifications.hasVorname(vorname));
}
And here at the
List<Telefonbuch> list = telefonbuchRepository.findAll(TelefonbuchSpecifications.hasVorname(vorname));
}
it tells me:
The method findAll(Sort) in the type JpaRepository<Telefonbuch,Long> is not applicable for the arguments (Specification<Telefonbuch>)