java – Spring Boot custom query returns relation todo does not exist

java – Spring Boot custom query returns relation todo does not exist

You have to change your query like below.

Your true statement should be like true instead of true only.

@RepositoryRestResource
@CrossOrigin(origins = http://localhost:4200)
public interface ToDoRepository extends JpaRepository<ToDo, Long> {
    @Query(value = SELECT * FROM ToDo WHERE taskCompleted = true, nativeQuery = true)
    Collection<ToDo> countCompletedTasks();
}

Create the default constructor for Todo entity.

java – Spring Boot custom query returns relation todo does not exist

Note that you could just use one of springs built in queries:

Collection<ToDo> findByTaskCompletedIsTrue();

If you really need the number only (as your methods name suggests), you can also use countBy

Long countByTaskCompletedIsTrue();

See the docs for more queries

Leave a Reply

Your email address will not be published. Required fields are marked *