4, HQL

Source: Internet
Author: User

1 , basic query

1, non-conditional query

2. Query with conditions

3, through the parameters of the query

4. Query by named parameters

5. Querying empty elements

2 , common query

1. List query (in ())

2. Projection Query

3, projection of an element query ( NOTE: You cannot use SELECT * to query )

4. Other types of projection

5. Single element query (Uniqueresult)

6, paging query

3 , Object-based queries, and SQL Native Query

There is also an object-based query in hibernate

Queries can be queried directly using SQL statements in Hibernate (occasionally used)

4 , connection query

4.1. SQL-based queries

Three ways to connect

1, internal connection (the two tables connected to have data connection)

SELECT * from t_student T1 JOIN t_classroom T2 on (t1.cla_id=t2.id)

The above data are data in both T_student and T_classroom.

2. Left Outer connection

SELECT * from T_classroom T1 left joins T_student T2 on (t2.cla_id=t1.id)

The result above is all the data on the left side of this table to connect to the data on the right table, if the right table has no data, it will be filled directly with NULL, which is very useful when doing statistics

3. Right outer connection

SELECT * from T_classroom T1 right JOIN t_student T2 on (t2.cla_id=t1.id)

The above is all the data from the right table, and if left table not, use NULL to populate

4.2, Hibernate-based connection query

1, using the object navigation link (a more convenient way of operation) limitation: only the internal connection

2, using the connection operation mode

3. Use left connection (exactly the same as SQL)

4. Use Right connection

4, HQL

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.