'The method findAll() in the type CrudRepository<Build,ObjectId> is not applicable for the arguments (Predicate)
I want to upgrade my spring boot project to 2.6.6 from 1.5.22.RELEASE while upgrading I'm getting the following errors suggest me how to fix it
The method findAll() in the type CrudRepository<Build,ObjectId> is not applicable for the arguments (Predicate)
The method findAll() in the type CrudRepository<Build,ObjectId> is not applicable for the arguments (Predicate, PageRequest)
Repository:
package com.capitalone.dashboard.repository;
import org.springframework.data.querydsl.QueryDslPredicateExecutor;
import org.springframework.data.repository.CrudRepository;
public interface BuildRepository extends CrudRepository<Build, ObjectId>, QueryDslPredicateExecutor<Build>
{
Build findByCollectorItemIdAndNumber(ObjectId collectorItemId, String number);
Build findByCollectorItemIdAndBuildUrl(ObjectId collectorItemId, String buildUrl);
...
}
Client code:
Iterable<Build> result;
if (request.getMax() == null) {
result = buildRepository.findAll(builder.getValue());
} else {
PageRequest pageRequest =PageRequest.of(0, request.getMax(), Sort.Direction.DESC, "timestamp");
result = buildRepository.findAll(builder.getValue(), pageRequest).getContent();
}
build.class
@Document(collection="builds")
public class Build extends BaseModel {
private ObjectId collectorItemId;
private long timestamp;
private String number;
I also tried changing to findAllById then got the below error :
The method findAllById() in the type CrudRepository<Build,ObjectId> is not applicable for the arguments (Predicate)
though the interface is extending QueryDslPredicateExecutor why I'm not able to use findAll(predicate)?
Solution 1:[1]
Looking at the API doc for CrudRepository and JpaRepository, I see that findaAll(Example<s> example) is only available in the JpaRepository interface. (I assume builder.getValue() in your code is a single value.)
For CrudRepository you would need to use findAllById(Iterable<ID> ids).
Thus, I suggest switching to JpaRepository or using findAllById.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Paulo Merson |
