Home > Back-end >  Spring Data JPA [Unknown column '...' in 'where clause']
Spring Data JPA [Unknown column '...' in 'where clause']

Time:11-12

I'm working on a Spring project, and MySQL database sysyem.

I have a table that has this column "list_id" and I have in Java class this variable for this column. However the two name are diffrent as you can see:

    @Column(name = "list_id")
    private int listId;

and I'm making this query:

   @Query(value="select * from words_list WHERE list_id=listId", nativeQuery=true)
   List<WordList> neverTested(@RequestParam("listId") int listId);

and I try to get them in the controller class

    public List<WordList> neverTested(@RequestParam int listId){

    return wordListRepository.neverTested(listId);
}

I always get this error:

java.sql.SQLSyntaxErrorException: Unknown column 'listId' in 'where clause'

even I'm sure of my way, but it sounds that the problem in the names

CodePudding user response:

Add a ":" before listId, like this:

 @Query(value="select * from words_list WHERE list_id = :listId", nativeQuery=true)
   List<WordList> neverTested(@RequestParam("listId") int listId);

CodePudding user response:

You have to write a colon before your parameter like this

 @Query(value="select * from words_list WHERE list_id=:listId", nativeQuery=true)
  • Related