Error - to create query for method public abstract org.springframework.data.domain.Page

1

I've been line by line to know what's different between an object that worked and what's going wrong and I can not find the problem. This Student object is giving error. If I comment on get sobe normal.

Code error:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'studentResource': Unsatisfied dependency expressed through field 'repository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.domain.Page com.school.repository.query.StudentRepositoryQuery.filtrar(com.school.repository.filter.StudentFilter,org.springframework.data.domain.Pageable)! No property filtrar found for type Student!

Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'studentRepository': Invocation of init method failed; nested exception is java.lang.IllegalArgumentException: Failed to create query for method public abstract org.springframework.data.domain.Page com.school.repository.query.StudentRepositoryQuery.filtrar(com.school.repository.filter.StudentFilter,org.springframework.data.domain.Pageable)! No property filtrar found for type Student!
Caused by: org.springframework.data.mapping.PropertyReferenceException: No property filtrar found for type Student!

Resource class:

public class StudentResource {
    @GetMapping
    public Page<Student> getFiltreEntity(StudentFilter studentFilter, Pageable pageable) {
        return repository.filtrar(studentFilter, pageable);
    }

Repository Class

public interface StudentRepository extends JpaRepository<Student, Long>, StudentRepositoryQuery{}

Query Class

public interface StudentRepositoryQuery {
    Page<Student> filtrar(StudentFilter studentFilter, Pageable pageable);
}

Impl Class

 public class StudentRepositoryImpl implements StudentRepositoryQuery{
        @Override
        public Page<Student> filtrar(StudentFilter studentFilter, Pageable pageable) {
                CriteriaBuilder builder = manager.getCriteriaBuilder();
                CriteriaQuery<Student> criteria = builder.createQuery(Student.class);
                Root<Student> root = criteria.from(Student.class);


                Predicate[] predicates = createFilter(studentFilter, builder, root);
                criteria.where(predicates);

                TypedQuery<Student> query = manager.createQuery(criteria);
                addPageRestrict(query, pageable);

            return new PageImpl<>(query.getResultList(), pageable, total(studentFilter));
        }

If you need the complete project here

    
asked by anonymous 27.09.2018 / 00:07

1 answer

1

In the StudentResource class you should add a variable / field of type StudentRepository or whatever you need and annotate with @Autowired. This would be the repository that is calling within the getFiltreEntity method.

I could see where the link between StudentRepositoryQuery and StudentRepository is.

    
28.09.2018 / 22:02