Query Result Processing

The result of a query is abstracted by the Result interface, which is an Iterable of Row. A Row is just a Map augmented with some convenience methods.

You can iterate over a Result:

Result result = ...

for (Row row : result) {

Or process it with the Stream API:

Result result = ...

result.forEach(r -> System.out.println(r.get("title"))); -> r.get("title")).forEach(System.out::println);

If your query is expected to return exactly one row you can access it with the single method:

Result result = ...

Row row = result.single();

If it optionally returns a result, like a find by id would, you can obtain it using first:

Result result = ...

Optional<Row> row = result.first();
row.ifPresent(r -> System.out.println(r.get("title")));

The element names and their types are checked only at runtime. Alternatively you can use interfaces to get typed access to the result data:

interface Book {
  String getTitle();
  Integer getStock();

Row row = ...
Book book =;

String title = book.getTitle();
Integer stock = book.getStock();

Interfaces can also be used to get a typed list or stream over the result:

Result result = ...



For the entities defined in the data model, CDS4j can generate interfaces for you through a Maven plugin.