String
String

Reputation: 3728

Pagination in Hibernate

I have a MySQL Strored Procedure ,I want to call the Stored Procedure using Hibernate and want to display the Results with Pagination.

I have tried the below Code:

public List<Master> getAbsentDetails(String fromdate, String todate,int pno) {
        Query query=getSession().getNamedQuery("AbsentReportproc");
        System.out.println("Test");
        query.setParameter("_fromdate", fromdate);
        query.setParameter("_todate", todate);
        query.setMaxResults(10);
        query.setFirstResult(ps*(pno-1));

        List<Master> empList=query.list();
        return empList;}

But when i Execute the above code I'm displayed with the following Error:

org.hibernate.util.JDBCExceptionReporter logExceptions
WARNING: SQL Error: 1064, SQLState: 42000
Feb 1, 2013 10:08:11 AM org.hibernate.util.JDBCExceptionReporter logExceptions
SEVERE: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'limit 10' at line 1

Note: If i remove the below statement

  query.setMaxResults(10);

then I'm displayed with Result of My Stored Procedure in a jsp page

thanks

Upvotes: 1

Views: 2636

Answers (1)

Suresh Atta
Suresh Atta

Reputation: 121998

when i faced the same issue i moved the set maxresult to below and working fine

criteria.setFirstResult(10* (pageNumber - 1));
criteria.setMaxResults(10); 

Upvotes: 2

Related Questions