Hibernatehql queries a specified field and obtains the result set.

Source: Internet
Author: User
In hibernate, the object class is queried using hql statements, and the returned result of the list method is a List. The objects encapsulated in the List are divided into three types: 1. query all fields.

In hibernate, the object class is queried using hql statements, and the returned result of the list method is a List. The objects encapsulated in the List are divided into three types: 1. query all fields.

In hibernate, the object class is queried using hql statements, and the returned result of the list method is a List. The objects encapsulated in the List are divided into the following three situations:
1. When you query all fields, such as "from object class", the objects encapsulated in the list are the object class, And all attributes are filled.
2. query only one field. By default,List encapsulates Object objects.
3. query two or more fields. By default, the list containsObject [], The length is consistent with the number of queried fields.

In the latter two cases, it is not convenient to use the Tag time, because it cannot be directly converted into an object of the object class. The simple solution is:

Usage: Used in hqlSelect new package name. Class Name (attribute 1, attribute 2 ......) From Object Class, add the constructor with parameters in the object class, the number and order of parameters and (attribute 1, attribute 2 ......) ConsistentIn this way, the list we get is still the object of the object class, And the queried attributes are filled, making it easier to use.

Partial: hql queries some fields in multiple tables,Select new package name. Table 1 Object Class Name (table 1. Attribute 1, Table 2. Attribute 2 ......) From table 1 entity class, Table 2 entity class where Table 1.ID= table 2.ID( that is, associated fields)At the same time, in the object class of Table 1 to be returned, add the attribute of table 2 and the Construction Method with parameters, the number and order of parameters and (table 1. attribute 1, table 2. attribute 2 ......) Consistent

For example, to query pid, score, title, totalAccept, totalSubmission, and unSee in Problem

The query statement is as follows:

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.