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.
- /**
- * @ Function displays the matched records in the database by Page Based on the passed objects.
- * @ Param pageNo
- * Current page number
- * @ Param pageSize
- * Number of records displayed on each page
- * @ Param object
- * Encapsulate query conditions as objects
- * @ Return encapsulate the query result as Pager returned
- */
- PublicPager findPageByExample (IntPageNo,IntPageSize, Object object)
- {
- Pager pager =Null;
- Try
- {
- Criteria criteria =This. GetSession (). createCriteria (
- Class. forName (This. GetEntity ()));
- If(Object! =Null)
- {
- Criteria. add (Example. create (object). enableLike ());
- }
- // Obtain the total number of rows queried by criteria by PAGE
- IntRowCount = (Integer) criteria. setProjection (
- Projections. rowCount (). uniqueResult ();
- Criteria. setProjection (Null);
- Criteria. setFirstResult (pageNo-1) * PageSize );
- Criteria. setMaxResults (pageSize );
- List result = criteria. list ();
- Pager =NewPager (pageSize, pageNo, rowCount, result );
- }Catch(RuntimeException re)
- {
- ThrowRe;
- }Finally
- {
- ReturnPager;
- }
- }