我有一個MySQL的過程,我想調用存儲過程使用休眠,並希望顯示結果分頁。分頁在休眠
我曾嘗試下面的代碼:
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;}
但是當我執行上面的代碼,我顯示以下錯誤:
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
注: 如果我刪除以下聲明
query.setMaxResults(10);
然後我
感謝
什麼是您的日誌級別設置爲爲了休眠?如果你把它設置爲ALL,我敢肯定你可以看到生成的查詢。 – djjolicoeur
其實你必須設置hibernate.show_sql屬性爲true才能看到生成的SQL。 –