I make a request to add the entire table to the List

public interface CourseRepository extends JpaRepository<CustomCourse, Long> { @Query("SELECT * FROM CustomCourse") CustomCourse findAllCourses(); } 

org.springframework.beans.factory.BeanCreationException: Error creating bean

Swears at the method, since it is without parameters, but I have no idea what to indicate there, because I am taking the entire table and not sampling for some field.

  • where 1 = ?, and substitute 1 - rjhdby
  • JpaRepository already has a findAll method, use it, besides the method should be List<CustomCourse> findAllCourses(); - MrFylypenko
  • Thank you, you helped me. In addition, I want to note that I was doing a SQL query, but I had to do JPQL. - Victor Morozov
  • Change your question and add what helped you. - MrFylypenko

1 answer 1

Firstly, my query "SELECT * FROM CustomCourse" was a SQL query, and it was more correct to make the JPQL query "SELECT c FROM CustomCourse c" once we use JPA and Hibernate.

Secondly, MrFylypenko correctly indicated that it was necessary to make the List findAllCourses () method; This allows you to do without cycles, and generally simplifies my work.

JpaRepository's findAll method also works.

As a result, my code looks like this

 @Query("SELECT c FROM CustomCourse c") ArrayList<CustomCourse> findAll();