0

when I ty to run this query

@Query(value = "select TOP(10) noleggi.id_libro, count(*) as occ from noleggi " +
            "group by noleggi.id_libro " +
            "order by occ desc",
    nativeQuery=true)

    List<Noleggio> findTop10();

Hibernate shows this error :

select TOP(10) noleggi.id_libro, count(*) as occ from noleggi group by noleggi.id_libro order by occ desc 2020-01-12 15:07:08.444 WARN 12316 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : SQL Error: 0, SQLState: S1093 2020-01-12 15:07:08.444 ERROR 12316 --- [nio-8080-exec-2] o.h.engine.jdbc.spi.SqlExceptionHelper : invalid column name id.

I don't use id, what do it means that?

baitmbarek
  • 2,440
  • 4
  • 18
  • 26
Max
  • 41
  • 2
  • 7
  • Your method is supposed to return a List. A Noleggio, I guess, has an ID. But your query doesn't return any ID. Use the correct return type. Your query actually returns a List. So that's what the return type should be. – JB Nizet Jan 12 '20 at 14:25
  • can you please describe table and Noleggio class – Mandar Dharurkar Jan 12 '20 at 14:29
  • my table noleggi has id PK, id_libro and user_id FK and my noleggio Class has public class Noleggio { private Long id; private LocalDate inizioPrestito; private LocalDate finePrestito; @JoinColumn(name = "id_utente") private Utente utente; @JoinColumn(name = "id_libro") private Libro libro; – Max Jan 12 '20 at 14:48

0 Answers0