3
votes
        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]

2
HQL is not SQL. It doesn't have any LIMIT clause. But you can set a max result on the Query itself. - JB Nizet
thanks for the help. - Yasitha Bandara

2 Answers

2
votes

try using the below

session.createSQLQuery("select * from AC_Customer order by customer_pk DESC LIMIT 1").list();
0
votes

org.hibernate.hql.internal.ast.QuerySyntaxException: unexpected token: OFFSET near line 1, column 87 [FROM om.omantel.prodsheet.models.RtcsProduct where status=1 order by TRACKING_ID DESC OFFSET 1 ROWS FETCH NEXT 5 ROWS ONLY]

    @SuppressWarnings("unchecked")
    @Override
     public List<RtcsProduct> pagination(int page_id, int total) {
    String listsql = "FROM RtcsProduct where status=1 order by TRACKING_ID DESC OFFSET "+page_id+" ROWS FETCH NEXT "+total+" ROWS ONLY";
    Session session = null;
    List<RtcsProduct> productlist = null;
    try {
    if (session == null) {
        session = sessionFactory.openSession();
        session.beginTransaction();
        productlist = session.createQuery(listsql).list();
        session.getTransaction().commit();

    }
    }catch(Exception ex) {
        ex.printStackTrace();
    }

    return productlist;
}