Spring Boot custom query returns relation “todo” does not exist











up vote
0
down vote

favorite












I'm currently writing my first Spring Boot application where I wan't to create a basic todo app.



The database works fine as long as I only use the CRUD functions and as soons as I call my own query I get this error:



2018-11-19 10:00:36.353 ERROR 25065 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path  threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: relation "todo" does not exist


My ToDoController:



package ch.aintevenmad.todo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

@RestController
public class ToDoController {
private ToDoRepository repository;

public ToDoController(ToDoRepository repository) {
this.repository = repository;
}

@GetMapping("/todo")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<ToDo> allToDo() {
return new ArrayList<>(repository.findAll());
}

@GetMapping("/first")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo firstToDo() {
return repository.findAll().get(0);
}

@GetMapping("/delete")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteToDo(ToDo toDo) {
repository.delete(toDo);
}

@GetMapping("/add")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo addToDO() {
Date date = new Date();
ToDo toDo = new ToDo("Hello", date, false);
repository.save(toDo);
return toDo;
}

@GetMapping("/countcompletedtasks")
@CrossOrigin(origins = "http://localhost:4200")
public int countCompletedTasks() {
return repository.countCompletedTasks().size();
}

@GetMapping("/deleteall")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteAll() {
repository.deleteAll();
}

@GetMapping("/loaddefaults")
@CrossOrigin(origins = "http://localhots:4200")
public void createDefaults() {
repository.save(new ToDo("PMB", false));
repository.save(new ToDo("GMDU", false));
repository.save(new ToDo("INMA", true));
repository.save(new ToDo("SLGP", false));
}

}


My ToDo Class:



package ch.aintevenmad.todo;

import lombok.*;

import javax.persistence.*;
import java.util.Date;

@Entity
@Data
@NoArgsConstructor
public class ToDo {
@Id
@GeneratedValue
private Long id;
private @NonNull
String taskName;
private Date dueDate;
private String extraNote;
private boolean taskCompleted;

public ToDo(String taskName, boolean taskCompleted) {
this.taskName = taskName;
this.taskCompleted = taskCompleted;
}
public ToDo(String taskName, Date dueDate, boolean taskCompleted) {
this.taskName = taskName;
this.dueDate = dueDate;
this.taskCompleted = taskCompleted;
}
}


My ToDoRepository:



package ch.aintevenmad.todo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.Collection;

@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();
}


Did I set up my project wrong or did I misunderstand how custom queries work with Spring Boot?



Thanks for any help!



EDIT: Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...










share|improve this question
























  • Can you check how the table is called in postgresql? Without going through Spring.
    – Tu.ma
    yesterday










  • Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
    – In0cenT
    yesterday










  • If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
    – a_horse_with_no_name
    yesterday















up vote
0
down vote

favorite












I'm currently writing my first Spring Boot application where I wan't to create a basic todo app.



The database works fine as long as I only use the CRUD functions and as soons as I call my own query I get this error:



2018-11-19 10:00:36.353 ERROR 25065 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path  threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: relation "todo" does not exist


My ToDoController:



package ch.aintevenmad.todo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

@RestController
public class ToDoController {
private ToDoRepository repository;

public ToDoController(ToDoRepository repository) {
this.repository = repository;
}

@GetMapping("/todo")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<ToDo> allToDo() {
return new ArrayList<>(repository.findAll());
}

@GetMapping("/first")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo firstToDo() {
return repository.findAll().get(0);
}

@GetMapping("/delete")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteToDo(ToDo toDo) {
repository.delete(toDo);
}

@GetMapping("/add")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo addToDO() {
Date date = new Date();
ToDo toDo = new ToDo("Hello", date, false);
repository.save(toDo);
return toDo;
}

@GetMapping("/countcompletedtasks")
@CrossOrigin(origins = "http://localhost:4200")
public int countCompletedTasks() {
return repository.countCompletedTasks().size();
}

@GetMapping("/deleteall")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteAll() {
repository.deleteAll();
}

@GetMapping("/loaddefaults")
@CrossOrigin(origins = "http://localhots:4200")
public void createDefaults() {
repository.save(new ToDo("PMB", false));
repository.save(new ToDo("GMDU", false));
repository.save(new ToDo("INMA", true));
repository.save(new ToDo("SLGP", false));
}

}


My ToDo Class:



package ch.aintevenmad.todo;

import lombok.*;

import javax.persistence.*;
import java.util.Date;

@Entity
@Data
@NoArgsConstructor
public class ToDo {
@Id
@GeneratedValue
private Long id;
private @NonNull
String taskName;
private Date dueDate;
private String extraNote;
private boolean taskCompleted;

public ToDo(String taskName, boolean taskCompleted) {
this.taskName = taskName;
this.taskCompleted = taskCompleted;
}
public ToDo(String taskName, Date dueDate, boolean taskCompleted) {
this.taskName = taskName;
this.dueDate = dueDate;
this.taskCompleted = taskCompleted;
}
}


My ToDoRepository:



package ch.aintevenmad.todo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.Collection;

@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();
}


Did I set up my project wrong or did I misunderstand how custom queries work with Spring Boot?



Thanks for any help!



EDIT: Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...










share|improve this question
























  • Can you check how the table is called in postgresql? Without going through Spring.
    – Tu.ma
    yesterday










  • Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
    – In0cenT
    yesterday










  • If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
    – a_horse_with_no_name
    yesterday













up vote
0
down vote

favorite









up vote
0
down vote

favorite











I'm currently writing my first Spring Boot application where I wan't to create a basic todo app.



The database works fine as long as I only use the CRUD functions and as soons as I call my own query I get this error:



2018-11-19 10:00:36.353 ERROR 25065 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path  threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: relation "todo" does not exist


My ToDoController:



package ch.aintevenmad.todo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

@RestController
public class ToDoController {
private ToDoRepository repository;

public ToDoController(ToDoRepository repository) {
this.repository = repository;
}

@GetMapping("/todo")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<ToDo> allToDo() {
return new ArrayList<>(repository.findAll());
}

@GetMapping("/first")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo firstToDo() {
return repository.findAll().get(0);
}

@GetMapping("/delete")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteToDo(ToDo toDo) {
repository.delete(toDo);
}

@GetMapping("/add")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo addToDO() {
Date date = new Date();
ToDo toDo = new ToDo("Hello", date, false);
repository.save(toDo);
return toDo;
}

@GetMapping("/countcompletedtasks")
@CrossOrigin(origins = "http://localhost:4200")
public int countCompletedTasks() {
return repository.countCompletedTasks().size();
}

@GetMapping("/deleteall")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteAll() {
repository.deleteAll();
}

@GetMapping("/loaddefaults")
@CrossOrigin(origins = "http://localhots:4200")
public void createDefaults() {
repository.save(new ToDo("PMB", false));
repository.save(new ToDo("GMDU", false));
repository.save(new ToDo("INMA", true));
repository.save(new ToDo("SLGP", false));
}

}


My ToDo Class:



package ch.aintevenmad.todo;

import lombok.*;

import javax.persistence.*;
import java.util.Date;

@Entity
@Data
@NoArgsConstructor
public class ToDo {
@Id
@GeneratedValue
private Long id;
private @NonNull
String taskName;
private Date dueDate;
private String extraNote;
private boolean taskCompleted;

public ToDo(String taskName, boolean taskCompleted) {
this.taskName = taskName;
this.taskCompleted = taskCompleted;
}
public ToDo(String taskName, Date dueDate, boolean taskCompleted) {
this.taskName = taskName;
this.dueDate = dueDate;
this.taskCompleted = taskCompleted;
}
}


My ToDoRepository:



package ch.aintevenmad.todo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.Collection;

@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();
}


Did I set up my project wrong or did I misunderstand how custom queries work with Spring Boot?



Thanks for any help!



EDIT: Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...










share|improve this question















I'm currently writing my first Spring Boot application where I wan't to create a basic todo app.



The database works fine as long as I only use the CRUD functions and as soons as I call my own query I get this error:



2018-11-19 10:00:36.353 ERROR 25065 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path  threw exception [Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessResourceUsageException: could not extract ResultSet; SQL [n/a]; nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet] with root cause

org.postgresql.util.PSQLException: ERROR: relation "todo" does not exist


My ToDoController:



package ch.aintevenmad.todo;

import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;

@RestController
public class ToDoController {
private ToDoRepository repository;

public ToDoController(ToDoRepository repository) {
this.repository = repository;
}

@GetMapping("/todo")
@CrossOrigin(origins = "http://localhost:4200")
public Collection<ToDo> allToDo() {
return new ArrayList<>(repository.findAll());
}

@GetMapping("/first")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo firstToDo() {
return repository.findAll().get(0);
}

@GetMapping("/delete")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteToDo(ToDo toDo) {
repository.delete(toDo);
}

@GetMapping("/add")
@CrossOrigin(origins = "http://localhost:4200")
public ToDo addToDO() {
Date date = new Date();
ToDo toDo = new ToDo("Hello", date, false);
repository.save(toDo);
return toDo;
}

@GetMapping("/countcompletedtasks")
@CrossOrigin(origins = "http://localhost:4200")
public int countCompletedTasks() {
return repository.countCompletedTasks().size();
}

@GetMapping("/deleteall")
@CrossOrigin(origins = "http://localhost:4200")
public void deleteAll() {
repository.deleteAll();
}

@GetMapping("/loaddefaults")
@CrossOrigin(origins = "http://localhots:4200")
public void createDefaults() {
repository.save(new ToDo("PMB", false));
repository.save(new ToDo("GMDU", false));
repository.save(new ToDo("INMA", true));
repository.save(new ToDo("SLGP", false));
}

}


My ToDo Class:



package ch.aintevenmad.todo;

import lombok.*;

import javax.persistence.*;
import java.util.Date;

@Entity
@Data
@NoArgsConstructor
public class ToDo {
@Id
@GeneratedValue
private Long id;
private @NonNull
String taskName;
private Date dueDate;
private String extraNote;
private boolean taskCompleted;

public ToDo(String taskName, boolean taskCompleted) {
this.taskName = taskName;
this.taskCompleted = taskCompleted;
}
public ToDo(String taskName, Date dueDate, boolean taskCompleted) {
this.taskName = taskName;
this.dueDate = dueDate;
this.taskCompleted = taskCompleted;
}
}


My ToDoRepository:



package ch.aintevenmad.todo;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.web.bind.annotation.CrossOrigin;

import java.util.Collection;

@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();
}


Did I set up my project wrong or did I misunderstand how custom queries work with Spring Boot?



Thanks for any help!



EDIT: Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...







java postgresql spring-boot






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited yesterday

























asked yesterday









In0cenT

54




54












  • Can you check how the table is called in postgresql? Without going through Spring.
    – Tu.ma
    yesterday










  • Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
    – In0cenT
    yesterday










  • If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
    – a_horse_with_no_name
    yesterday


















  • Can you check how the table is called in postgresql? Without going through Spring.
    – Tu.ma
    yesterday










  • Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
    – In0cenT
    yesterday










  • If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
    – a_horse_with_no_name
    yesterday
















Can you check how the table is called in postgresql? Without going through Spring.
– Tu.ma
yesterday




Can you check how the table is called in postgresql? Without going through Spring.
– Tu.ma
yesterday












Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
– In0cenT
yesterday




Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table...
– In0cenT
yesterday












If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
– a_horse_with_no_name
yesterday




If you found a solution, then post that solution as an answer, do not edit your question for that. It's perfectly acceptable to answer your own question (and accept your own answer)
– a_horse_with_no_name
yesterday












5 Answers
5






active

oldest

votes

















up vote
-1
down vote



accepted










Just writing the solution as an answer instead of as a comment.



You should check using a third-party client (not your spring application) the name of the relation in the database. Hibernate is probably giving it a different name.






share|improve this answer





















  • I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
    – Tu.ma
    yesterday


















up vote
1
down vote













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();
}





share|improve this answer




























    up vote
    0
    down vote













    Note that you could just use one of spring's built in queries:



    Collection<ToDo> findByTaskCompletedIsTrue();


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



    Long countByTaskCompletedIsTrue();


    See the docs for more queries






    share|improve this answer




























      up vote
      0
      down vote













      Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table.






      share|improve this answer




























        up vote
        -1
        down vote













        Create the default constructor for Todo entity.






        share|improve this answer





















        • @NoArgsConstructor does it for him.
          – Tu.ma
          yesterday











        Your Answer






        StackExchange.ifUsing("editor", function () {
        StackExchange.using("externalEditor", function () {
        StackExchange.using("snippets", function () {
        StackExchange.snippets.init();
        });
        });
        }, "code-snippets");

        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "1"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














         

        draft saved


        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371462%2fspring-boot-custom-query-returns-relation-todo-does-not-exist%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        5 Answers
        5






        active

        oldest

        votes








        5 Answers
        5






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes








        up vote
        -1
        down vote



        accepted










        Just writing the solution as an answer instead of as a comment.



        You should check using a third-party client (not your spring application) the name of the relation in the database. Hibernate is probably giving it a different name.






        share|improve this answer





















        • I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
          – Tu.ma
          yesterday















        up vote
        -1
        down vote



        accepted










        Just writing the solution as an answer instead of as a comment.



        You should check using a third-party client (not your spring application) the name of the relation in the database. Hibernate is probably giving it a different name.






        share|improve this answer





















        • I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
          – Tu.ma
          yesterday













        up vote
        -1
        down vote



        accepted







        up vote
        -1
        down vote



        accepted






        Just writing the solution as an answer instead of as a comment.



        You should check using a third-party client (not your spring application) the name of the relation in the database. Hibernate is probably giving it a different name.






        share|improve this answer












        Just writing the solution as an answer instead of as a comment.



        You should check using a third-party client (not your spring application) the name of the relation in the database. Hibernate is probably giving it a different name.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered yesterday









        Tu.ma

        500115




        500115












        • I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
          – Tu.ma
          yesterday


















        • I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
          – Tu.ma
          yesterday
















        I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
        – Tu.ma
        yesterday




        I am wondering about the meaning of the downvote: this is the solution and the OP confirmed it.
        – Tu.ma
        yesterday












        up vote
        1
        down vote













        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();
        }





        share|improve this answer

























          up vote
          1
          down vote













          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();
          }





          share|improve this answer























            up vote
            1
            down vote










            up vote
            1
            down vote









            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();
            }





            share|improve this answer












            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();
            }






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered yesterday









            GauravRai1512

            72210




            72210






















                up vote
                0
                down vote













                Note that you could just use one of spring's built in queries:



                Collection<ToDo> findByTaskCompletedIsTrue();


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



                Long countByTaskCompletedIsTrue();


                See the docs for more queries






                share|improve this answer

























                  up vote
                  0
                  down vote













                  Note that you could just use one of spring's built in queries:



                  Collection<ToDo> findByTaskCompletedIsTrue();


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



                  Long countByTaskCompletedIsTrue();


                  See the docs for more queries






                  share|improve this answer























                    up vote
                    0
                    down vote










                    up vote
                    0
                    down vote









                    Note that you could just use one of spring's built in queries:



                    Collection<ToDo> findByTaskCompletedIsTrue();


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



                    Long countByTaskCompletedIsTrue();


                    See the docs for more queries






                    share|improve this answer












                    Note that you could just use one of spring's built in queries:



                    Collection<ToDo> findByTaskCompletedIsTrue();


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



                    Long countByTaskCompletedIsTrue();


                    See the docs for more queries







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered yesterday









                    bambam

                    43.9k871112




                    43.9k871112






















                        up vote
                        0
                        down vote













                        Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table.






                        share|improve this answer

























                          up vote
                          0
                          down vote













                          Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table.






                          share|improve this answer























                            up vote
                            0
                            down vote










                            up vote
                            0
                            down vote









                            Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table.






                            share|improve this answer












                            Thanks Tu.ma you found the problem. Postgresql didnt call the table todo as expected but to_do so of course it didn't fine the table.







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered yesterday









                            In0cenT

                            54




                            54






















                                up vote
                                -1
                                down vote













                                Create the default constructor for Todo entity.






                                share|improve this answer





















                                • @NoArgsConstructor does it for him.
                                  – Tu.ma
                                  yesterday















                                up vote
                                -1
                                down vote













                                Create the default constructor for Todo entity.






                                share|improve this answer





















                                • @NoArgsConstructor does it for him.
                                  – Tu.ma
                                  yesterday













                                up vote
                                -1
                                down vote










                                up vote
                                -1
                                down vote









                                Create the default constructor for Todo entity.






                                share|improve this answer












                                Create the default constructor for Todo entity.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered yesterday









                                darshakat

                                341110




                                341110












                                • @NoArgsConstructor does it for him.
                                  – Tu.ma
                                  yesterday


















                                • @NoArgsConstructor does it for him.
                                  – Tu.ma
                                  yesterday
















                                @NoArgsConstructor does it for him.
                                – Tu.ma
                                yesterday




                                @NoArgsConstructor does it for him.
                                – Tu.ma
                                yesterday


















                                 

                                draft saved


                                draft discarded



















































                                 


                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53371462%2fspring-boot-custom-query-returns-relation-todo-does-not-exist%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                404 Error Contact Form 7 ajax form submitting

                                How to know if a Active Directory user can login interactively

                                TypeError: fit_transform() missing 1 required positional argument: 'X'