Skip to content

Latest commit

 

History

History
32 lines (28 loc) · 2.3 KB

repository-query-return-types-reference.adoc

File metadata and controls

32 lines (28 loc) · 2.3 KB

Repository query return types

Supported query return types

The following table lists the return types generally supported by Spring Data repositories. However, consult the store-specific documentation for the exact list of supported return types, because some listed here might not be supported in a particular store.

Note
Geospatial types like (GeoResult, GeoResults, GeoPage) are only available for data stores that support geospatial queries.
Table 1. Query return types
Return type Description

void

Denotes no return value.

Primitives

Java primitives.

Wrapper types

Java wrapper types.

T

An unique entity. Expects the query method to return one result at most. In case no result is found null is returned. More than one result will trigger an IncorrectResultSizeDataAccessException.

Iterator<T>

An Iterator.

Collection<T>

A Collection.

List<T>

A List.

Optional<T>

A Java 8 or Guava Optional. Expects the query method to return one result at most. In case no result is found Optional.empty()/Optional.absent() is returned. More than one result will trigger an IncorrectResultSizeDataAccessException.

Stream<T>

A Java 8 Stream.

Future<T>

A Future. Expects method to be annotated with @Async and requires Spring’s asynchronous method execution capability enabled.

CompletableFuture<T>

A Java 8 CompletableFuture. Expects method to be annotated with @Async and requires Spring’s asynchronous method execution capability enabled.

ListenableFuture

A org.springframework.util.concurrent.ListenableFuture. Expects method to be annotated with @Async and requires Spring’s asynchronous method execution capability enabled.

Slice

A sized chunk of data with information whether there is more data available. Requires a Pageable method parameter.

Page<T>

A Slice with additional information, e.g. the total number of results. Requires a Pageable method parameter.

GeoResult<T>

A result entry with additional information, e.g. distance to a reference location.

GeoResults<T>

A list of GeoResult<T> with additional information, e.g. average distance to a reference location.

GeoPage<T>

A Page with GeoResult<T>, e.g. average distance to a reference location.