shop++ Criteriaquery Database Query statements

Source: Internet
Author: User

The criteria query statement for hibernate is a more object-oriented approach to querying.

Criteriabuilder Criteriabuilder = Entitymanager.getcriteriabuilder (); Create a Entitymanager to create a criteriabuilder real column criteriaquery<t> criteriaquery = Criteriabuilder.createquery ( Entityclass);//criteriabuilder creates a createquery real column, Criteriaquery is given a generic type, and the generic parameter declares the type of result that criteriaquery returns at execution time.

Criteriaquery.select (Criteriaquery.from (Entityclass)); Set up a query expression on Criteriaquery

Return Findlist (Criteriaquery, First, count, filters, orders);//return result set

 

hibernate
String jpql =" Select COUNT (*) from agent agent where lower (agent.name) = lower (: name) ";//Create JPQL statement (it should be noted that the agent behind the from is an entity bean and not a data table.) )
 long count = Entitymanager.createquery (JPQL, Long.class)// Get a createquery real column from Entitymanager, the first position is the JPQL statement, the second position is the reflection object, and the object is the type  .setflushmode (flushmodetype.commit) of the return value. Setparameter ("name", name)//Refresh when the query executes. Set query parameters. Getsingleresult ();//Returns a single result

Through the comparison between the two statements can deepen the deep understanding of criteriaquery query statements, of course, the premise is to be familiar with a language.in the shop++ program,It is recommended to use JPQL statements when using generic queries, because implementing a simple query, for example, also createsEntitymanager then create a createquery real column. This virtually increases the code, and the Code execution efficiency is reduced a lot. Of course, if you want to do a slightly more complex query, such as dynamic query, you need to increase the number of conditions, sorting and so on the condition query can be used criteriaquery query statements.

shop++ Criteriaquery Database Query statements

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.