From da3dd8b2158c555605ec6a741bd08edcce8dd0c1 Mon Sep 17 00:00:00 2001 From: "robin.bygrave" Date: Wed, 10 Jun 2026 16:31:36 +1200 Subject: [PATCH] docs: findStream() preferred over findList().stream() --- docs/guides/writing-ebean-query-beans.md | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/docs/guides/writing-ebean-query-beans.md b/docs/guides/writing-ebean-query-beans.md index 3e7ee9cdc..ebcbd8989 100644 --- a/docs/guides/writing-ebean-query-beans.md +++ b/docs/guides/writing-ebean-query-beans.md @@ -77,6 +77,7 @@ often the right query shape. | Check if at least one row exists | `exists()` | Cheapest choice for boolean existence checks | | Load exactly one row by ID or unique key | `findOne()` | Only use when the predicate is truly unique | | Load a list of entity beans | `findList()` | Default for list screens and domain logic | +| Stream rows, usually to map into another type | `findStream()` | Prefer over `findList().stream()`; streams from the JDBC cursor, then `.map(...).toList()` | | Count matching rows | `findCount()` | Prefer over loading entities just to count | | Load a page plus optional total row count | `findPagedList()` | Use when the caller needs pagination metadata | | Return DTO/read-model rows | `asDto(...).findList()` | Prefer this over partially loaded entities for API/view models | @@ -99,6 +100,21 @@ Customer customer = new QCustomer() Do **not** use `findOne()` for predicates that can match multiple rows. +### Example - stream and map to another type + +Use `findStream()` (not `findList().stream()`) when you immediately transform +each row into another type. It streams from the JDBC cursor rather than +materialising the full entity list first. + +```java +List pending = new QCaptureRequest() + .collectedAt.isNull() + .orderBy().requestedAt.asc() + .findStream() + .map(r -> new PendingPlan(r.app().getName(), r.hash())) + .toList(); +``` + --- ## Step 3 - Build predicates by traversing properties and associations