2.10.2.8.1. JPQL Result Type of the SELECT Clause
The type of the query result specified by the SELECT clause of a query is an entity abstract schema type, a state-field type, the result of of a scalar expression, the result of an aggregate function, the result of a construction operation, or some sequence of these.
The result type of the SELECT clause is defined by the result types of the select_expressions contained in it.
When multiple select expressions are used in the SELECT clause, the result of the query is of type Object[], and the elements in this result correspond in order to the order of their specification in the SELECT clause and in type to the result types of each of the select expressions.
The type of the result of a select_expression is as follows:
-
The result type of an
identification_variableis the type of the entity object or embeddable object to which the identification variable corresponds. The type of anidentification_variablethat refers to an entity abstract schema type is the type of the entity to which that identification variable corresponds or a subtype as determined by the object/relational mapping. -
The result type of a
single_valued_path_expressionthat is astate_field_path_expressionresults in an object of the same type as the corresponding state field of the entity or embeddable class. If the state field of the entity is a primitive type, the result type is the corresponding object type. -
The result type of a
single_valued_path_expressionthat is asingle_valued_object_path_expressionis the type of the entity object or embeddable object to which the path expression corresponds. Asingle_valued_object_path_expressionthat results in an entity object will result in an entity of the type of the relationship field or the subtype of the relationship field of the entity object as determined by the object/relational mapping. -
The result type of a
single_valued_path_expressionthat is an identification_variable to which theKEYorVALUEfunction has been applied is determined by the type of the map key or value respectively, as defined by the above rules -
The result type of a
single_valued_path_expressionthat is anidentification_variableto which theENTRYfunction has been applied isjava.util.Map.Entry, where the key and value types of the map entry are determined by the above rules as applied to the map key and map value respectively. -
The result type of a
scalar_expressionis the type of the scalar value to which the expression evaluates. The result type of a numericscalar_expressionis defined in JPQL Scalar Expressions -
The result type of an
entity_type_expressionscalar expression is the Java class to which the resulting abstract schema type corresponds. -
The result type of aggregate_expression is defined in JPQL Aggregate Functions.
-
The result type of a
constructor_expressionis the type of the class for which the constructor is defined. The types of the arguments to the constructor are defined by the above rules.