Reputation: 2375
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]
Upvotes: 4
Views: 10395
Reputation: 9469
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()
Upvotes: 2
Reputation: 460
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;
}
Upvotes: 0
Reputation: 37
try using the below
session.createSQLQuery("select * from AC_Customer order by customer_pk DESC LIMIT 1").list();
Upvotes: 3