Hibernate 查詢說明

來源:互聯網
上載者:User

標籤:blog   http   io   ar   os   使用   java   資料   on   

1、Criteria 
setFetchSize實際上與分頁操作並沒有關係,它的作用是在查詢中進行分批資料返回,其中的值就是每次分批查詢的記錄數,主要是為了提高查詢效能的.

舉個例子來說:
如果你這次查詢一共是50條結果,如果你這裡設定了setFetchSize(5);則JDBC會5條5條的將資料返回給Java對象,而如果不設定,則是一起返回.

這個方法在java.sql.Statement和ResultSet中也有,功能是一樣的,你可以參考一下.
如果要分頁還是要使用setMaxResults來完成.

2、hql查詢
ScrollableResults rs=session.createQuery("from Customer c").scroll;//遊標移動到結果集的第一行rs.first();Object[] o=rs.get();Customer customer=(Customer)o[0];//擷取對象數組的第一個對象System.out.println(customer.getId());rs.scroll(2);//遊標從當前的位置移動2行Customer customer=(Customer)rs.get(0);//擷取當前行中的第一個欄位,為Customer對象System.out.println(customer.getId());rs.close();

轉自:http://zhidao.baidu.com/question/105546781.html
http://m.blog.csdn.net/blog/yu422560654/7277568


Hibernate 查詢說明

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.