Query Return Types
About
In JPA, query return types refer to the kind of data you expect back when executing a query (JPQL, Criteria, or Native SQL). Depending on the query and the method used, JPA can return:
Single entities
Scalar values (like
Long,String,Integer)DTOs (custom projections)
Aggregates
Tuples (multiple fields)
Collections
Characteristics
Return Type
Description
Entity
Returns full entity objects (mapped to a table).
DTO/Projection
Returns only selected fields using constructor expressions or interfaces.
Scalar
Returns basic types (e.g., count, sum, string).
List
Returns multiple results.
Single Result
Returns one result or throws exception if not found or more than one.
Tuple/Array
Returns multiple selected columns (e.g., in projections).
Syntax Structure
1. Entity Object (Default)
2. Scalar Value
3. Multiple Scalar Values (Array or Tuple)
4. DTO via Constructor Expression (JPQL)
DTO class
5. DTO via Interface (Spring Projections)
6. Single Result
Last updated