I'm new to spring. I would like to add pagination to my apis but I keep getting this error
oracle.jdbc.OracleDatabaseException: ORA-00904: "R" : invalid identifier
"R"
is the alias of my table in this query
Repository
@Query(
value ="select * from students r inner join conf c on r.status_id = c.id where c.code = 'NEW'",
nativeQuery = true
)
Page<Student> findNewStudents(Pageable pageable);
this is just a simple query but I have also some LONG queries
I searched a lot I found that countQuery
should be added and effictively it worked for me
@Query(
value ="select * from students r inner join conf c on r.status_id = c.id where c.code ='NEW'",
countQuery ="select count(*) from students r inner join conf c on r.status_id = c.id where c.code = 'NEW'" ,
nativeQuery = true
)
Page<Student> findNewStudents(Pageable pageable);
but according to this answer
countQuery
is not needed since Spring Boot 2.4.3 and I'm using Spring Boot 2.7.1 but I got the error above if don't use it.
as I said with countQuery
it works but I have some long queries it's bit hard to have the query of counting also!
UPDATE
after enabling sql log, I got
2022-08-14 23:30:07.384 DEBUG 10996 --- [nio-8080-exec-1] org.hibernate.SQL : select * from students r inner join conf c on r.status_id = c.id where c.code ='NEW' fetch first ? rows only
2022-08-14 23:30:07.525 DEBUG 10996 --- [nio-8080-exec-1] org.hibernate.SQL: select count(r) from students r inner join conf c on r.status_id = c.id where c.code = 'NEW'
Thanks in advance