4
        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]

Yasitha Bandara
  • 1,995
  • 2
  • 14
  • 20

3 Answers3

2

try using the below

session.createSQLQuery("select * from AC_Customer order by customer_pk DESC LIMIT 1").list();
Gal Dreiman
  • 3,969
  • 2
  • 21
  • 40
1

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()
michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
0

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;
}
Deepak Singh
  • 460
  • 2
  • 7
  • 19