I am trying to run a Hibernate
query that returns all the rows except the last 5 five rows, so my sql query is as follow:
session.createQuery("FROM Book
WHERE id NOT IN(SELECT id FROM Book ORDER BY ID DESC LIMIT 5)
ORDER BY title");
Unfortunately, the LIMIT
not allowed in Hibernate
, so I got an error saying:
HTTP Status 500 - org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LIMIT near line 1, column 78 [FROM models.Book WHERE id NOT IN(SELECT id FROM models.Book ORDER BY ID DESC LIMIT 5) ORDER BY title]
How I can fix this?