> For the complete documentation index, see [llms.txt](https://coldbox-orm.ortusbooks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://coldbox-orm.ortusbooks.com/v5.x/advanced/java-streams.md).

# Java Streams

Stream results from the database with native Java streams

cborm 6 returns native Java streams, built by `bx-orm`: no extra module is needed (cbStreams is no longer a dependency). Pass `asStream = true` to `list()`, `executeQuery()`, `findAll()`, `findAllWhere()`, `getAll()` or a dynamic finder, or call `asStream()` on a criteria query.

A stream reads the rows from the database as you consume it, so a large result never sits in memory at once. BoxLang closures work with every stream method:

```javascript
// names of the active users, read row by row
var names = userService.list( asStream = true )
    .filter( ( user ) => user.getIsActive() )
    .map( ( user ) => user.getFullName() )
    .toList();

// count without building an array
var total = ormService.findAllWhere( entityName = "Order", criteria = { status : "open" }, asStream = true ).count();

// criteria
var emails = ormService.newCriteria( "User" )
    .isTrue( "isActive" )
    .asStream()
    .list()
    .map( ( user ) => user.getEmail() )
    .toList();
```

{% hint style="warning" %}
A stream holds an open database cursor until it is exhausted or closed, so consume it in the same request. Hibernate closes it with the session at the latest.
{% endhint %}

## Rules

* A unique query (`unique = true`) or an update/delete cannot be streamed: `bx-orm` raises an `orm.argument` error. A `findBy...` dynamic finder with `asStream` returns a stream of zero or one entity.
* `asQuery` does not apply to streams.

## Coming from cbStreams

cborm 5 returned [cbStreams](https://forgebox.io/view/cbstreams) streams. The native stream has the same core methods (`filter`, `map`, `reduce`, `forEach`, `count`, `anyMatch`, `sorted`, `limit`, `skip`, ...). If you rely on a cbStreams-only method, install cbStreams yourself and build one from the array result: `streamBuilder.new( ormService.list( "User" ) )`.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://coldbox-orm.ortusbooks.com/v5.x/advanced/java-streams.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
