Good day. In a working Spring MVC application, I try to configure my own request in an interface that extends the CrudRepository JPA, but the IDE does not accept the request at all. Here is the request itself:

@Query (value = "Select b FROM Books WHERE Books.BOOK_TITLE LIKE ? AND Books.autor LIKE ?", nativeQuery = true) List<Books> listAllBooks(); 

In response, the IDE emphasizes AND and reports: number expected, got AND. How to fix?

Even if you create a simple query like:

 @Query (value = "Select b.autor FROM Books b", nativeQuery = true) List<Books> listAllBooks(); 

That IDE emphasizes Books and does not define it as an entity.

The application itself is published on github: https://github.com/oleggalimov/books

Help please understand and fix. And most importantly, how is it possible to properly create such requests?

  • Perhaps this is not the IDE itself, it also stresses all entities in red, but everything works like clockwork. Do you only emphasize or do not work? - JVic
  • You are trying to use clean sql: nativeQuery = true , instead of hql, try to remove this parameter - MrFylypenko
  • Indeed, compiles without problems. - Oleg

2 answers 2

  1. You can specify columns in quotes.

     @Query (value = "Select b FROM Books WHERE \"Books.BOOK_TITLE\" LIKE ? AND \"Books.autor\" LIKE ?", nativeQuery = true) 
  2. Disable verification in IDE settings

     Settings -> Incpections -> Jpa issues "Unresolved queries and query parameter" снять галочку 
  • Indeed, if the application is compiled in spite of underscores, without editing the query. - Oleg
  • I rewrote the query: @Query (value = "select b from Books b where b.autor like concat ('%', autor, '%') or b.izdatel like concat ('%', izdatel, '%')" ) List <Books> listAllBooks1 (@Param ("autor") String name, @Param ("izdatel") String izdatel); - Oleg
  • But when I execute this request, I already get the error: HTTP Status 500 - Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageException: org.hibernate.QueryParameterException: Remember that ordinal parameters are 1-based! Position: 1; nested exception is java.lang.IllegalArgumentException: org.hibernate.QueryParameterException: Remember that ordinal parameters are 1-based! Position: 1 - Oleg

Found a solution:

  1. The IDE does emphasize the name of the entity, but the application compiles and runs without problems. Thanks @Nicolas Chabanovsky ♦, @ Victor, @MrFylypenko!
  2. The error "... Position beyond the number of declared ordinal parameters .." is due to the fact that there is no colon before the parameters. All good and plus to karma! :)