Hibernate page summary

Source: Internet
Author: User

Hibernate is usually used in three types: hql query, QBC query, and QBE query:
1. QBE (Qurey By Example) Retrieval Method

QBE is the simplest, but its function is also the weakest. It is not very powerful and only useful in some scenarios. A typical application scenario is to allow users to enter a series of query conditions in the query window and then return matched objects. QBE only supports the = and like comparison operators, and cannot match a small interval value or its or. In this case, the HQL or QBC retrieval method is used.

  1. /** 
  2. * @ Function displays the matched records in the database by Page Based on the passed objects. 
  3. * @ Param pageNo 
  4. * Current page number 
  5. * @ Param pageSize 
  6. * Number of records displayed on each page 
  7. * @ Param object 
  8. * Encapsulate query conditions as objects 
  9. * @ Return encapsulate the query result as Pager returned 
  10. */
  11. PublicPager findPageByExample (IntPageNo,IntPageSize, Object object)
  12. {
  13. Pager pager =Null;
  14. Try
  15. {
  16. Criteria criteria =This. GetSession (). createCriteria (
  17. Class. forName (This. GetEntity ()));
  18. If(Object! =Null)
  19. {
  20. Criteria. add (Example. create (object). enableLike ());
  21. }
  22. // Obtain the total number of rows queried by criteria by PAGE
  23. IntRowCount = (Integer) criteria. setProjection (
  24. Projections. rowCount (). uniqueResult ();
  25. Criteria. setProjection (Null);
  26. Criteria. setFirstResult (pageNo-1) * PageSize );
  27. Criteria. setMaxResults (pageSize );
  28. List result = criteria. list ();
  29. Pager =NewPager (pageSize, pageNo, rowCount, result );
  30. }Catch(RuntimeException re)
  31. {
  32. ThrowRe;
  33. }Finally
  34. {
  35. ReturnPager;
  36. }
  37. }

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.