Summary of common retrieval methods of The hibernate framework in JSP development, and hibernate Retrieval Methods
Summary common retrieval methods of The hibernate framework
1. The hibernate framework can be searched in the following ways:
- OID retrieval: Retrieves data based on the unique id oid.
- Object navigation retrieval: queries object data associated with an object based on the object navigation.
- HQL search: query through the query interface object
- QBC search: Query through the criteria interface object
- SQL search: Query through SQL statements
2. HQL retrieval method:
- Query all data: session. createQuery ("from Class Name ");
- Query by condition: session. createQuery ("from class name where attribute name =? "). SetParameter (? Number index (starting from 0), condition );
- Paging Query: query = session. createQuery ("from Class Name"); ----- query. setFirstResult (start index); ---- Query. setMaxResults (number of records displayed on each page );
- Statistical query: session. createQuery ("select count (*) from Class Name"). uniqueResult ();
- Projection query (query a field or a part of the field): session. createQuery ("select attribute name 1, attribute name 2 from Class Name ");
- Alias query: session. createQuery ("select alias from class name alias ");
3. QBC retrieval method:
- Query all data: session. createCriteria (class name. class). list ();
- Query by condition: session. createCriteria (class name. class). add (Restrictions. Condition Method Name ("attribute name", condition ));
- Paging query: Criteria criteria = session. createCriteria (class name. class); ---- criteria. setFirstResult (Starting index); ----- criteria. setMaxResults (number of records displayed on each page );
- Sort query: session. createCriteria (class name. class). addOrder (Order. asc/desc ("attribute name "));
- Statistical query: session. createCriteria (class name. class). addProjection (Projections. rowCount ());
- Offline conditional query: (this can solve the problem of splicing complex SQL statements in the persistent layer)
Thank you for reading this article. I hope it will help you. Thank you for your support for this site!