Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

unexpected token: LIMIT error in hql

Tags:

hibernate

hql

        List<AC_Customer> lastAC_CustomersList = session.createQuery("from AC_Customer order by customer_pk DESC LIMIT 1").list()

when i execute this i got this error can any one please tell me what is wron with my hql query.

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: LIMIT near line 1, column 65 [from com.softlogic.models.AC_Customer order by customer_pk DESC LIMIT 1]

like image 583
Yasitha Bandara Avatar asked Sep 14 '25 09:09

Yasitha Bandara


2 Answers

try using the below

session.createSQLQuery("select * from AC_Customer order by customer_pk DESC LIMIT 1").list();
like image 113
Keshore Durairaj Avatar answered Sep 17 '25 20:09

Keshore Durairaj


HQL does not know LIMIT you have to use setMaxResults in a following way:

List<AC_Customer> lastAC_CustomersList = session
    .createQuery("from AC_Customer order by customer_pk DESC")
    .setMaxResults(1)
    .getResultList()
like image 45
michal.jakubeczy Avatar answered Sep 17 '25 19:09

michal.jakubeczy