upog
upog

Reputation: 5531

Spring data JPA - specification

I'm facing issues when passing specification to the repository.findAll()

Version:spring-boot-starter-data-jpa-2.2.4.RELEASE

Repository

@Repository
public interface ServerAttributesRepository extends JpaRepository<ServerAttributes, Integer>{
    public ServerAttributes findById(int Id);
}

and when I call repository.findAll by passing specification, I get error

ServerAttributeSpecification spec1 = new ServerAttributeSpecification(
            new SearchCriteria("server", SearchOperation.EQUALITY, "1"));
    List<ServerAttributes> serverAttributesList = serverAttributesRepository.findAll(spec1);

Error:

Cannot resolve method 'findAll(com.cloud.compareService.specification.ServerAttributeSpecification)'

and I can not find findAll(Specification<T> spec) in my JpaRepository

enter image description here

reference: https://www.baeldung.com/rest-api-query-search-language-more-operations

Upvotes: 0

Views: 771

Answers (1)

Pistolnikus
Pistolnikus

Reputation: 366

You need to extend JpaSpecificationExecutor interface to get support for Specifications, so try:

@Repository
public interface ServerAttributesRepository extends JpaRepository<ServerAttributes, Integer>, JpaSpecificationExecutor<ServerAttributes> {
    public ServerAttributes findById(int Id);
}

Upvotes: 1

Related Questions