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

Asked

Viewed 1,529 times

0

I’ve been line by line to find out what’s different between an object that’s worked and what’s going wrong and I can’t find the problem. This Student object is giving error. If I comment the get goes up 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);
}

Classe Impl

 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 is here

  • Try renaming StudentRepositoryImpl for StudentRepositoryQueryImpl. If it works, let me know and I’ll create an appropriate response.

  • @Statelessdev The error still continues. The others that work are also missing from the query.

2 answers

1

In the Studentresource class you should add a Studentrepository variable/field 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.

0

Dude, for me it worked by changing the extension order in the Repository class

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

would look like this:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.