Summary of common retrieval methods of The hibernate framework in JSP development, and hibernate Retrieval Methods

Source: Internet
Author: User

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:

  1. OID retrieval: Retrieves data based on the unique id oid.
  2. Object navigation retrieval: queries object data associated with an object based on the object navigation.
  3. HQL search: query through the query interface object
  4. QBC search: Query through the criteria interface object
  5. 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!

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.