Conditional query, SQL, JPQL, hql comparison

Source: Internet
Author: User

I. Definition of JPQL

In Java EE, JPQL (Java Persistence Query Language) is designed specifically for Java applications to access and navigate entity instances. JPQL is an extension of the query language EJB QL used by EJB2, which inherits the EJB QL and makes some changes to it.

Second, JPQL and SQL

PQL is an object-oriented query language, so it can fully understand the characteristics of inheritance, polymorphism, and correlation. And JPQL has built-in a lot of functions, greatly facilitates the function of JPQL query. Of course JPQL is still SQL-based, but the JPQL-to-SQL conversion does not need to be a developer's concern, and the JPQL parser is responsible for completing this transformation, and is responsible for executing the SQL statement to update the database.
SQL is a query language for relational databases, so the objects for SQL operations are data tables, data columns, and objects that JQPL manipulate are entity objects, object properties.

Code comparison

Sql:

Native SQL statement Select name,age,user_id from T_user

JPQL:

Analysis:
The first statement is used to execute a query against the T_user table tables, querying the name, age, and user_id three data columns;
The second statement is used to execute a query against the user entity, querying the name, age, and UserId properties of the user entity.

Third, HQL

HQL (Hibernate query Language) is an object-oriented query, followed by a "table name", where the condition is followed by "fields in the table." When you use queries in Hibernate,
Generally use HQL query statements. Because HQL is object-oriented, and the names and properties of object classes are case-sensitive, they are case-sensitive

Conditional query, SQL, JPQL, hql comparison

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.