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: