# How to call stream() on the Hibernate CriteriaImpl object

**URL:** <https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144>\
**Category:** Hibernate ORM\
**Created:** [August 1, 2018, 10:09am UTC](https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144 "2018-08-01T10:09:35Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![caristu](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@caristu](https://discourse.hibernate.org/u/caristu)\
**Post date:** [August 1, 2018, 10:09am UTC](https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144/1 "2018-08-01T10:09:35Z")

</div>

Hello,

I have a class that extends `org.hibernate.internal.CriteriaImpl` but as far as I can see the API of that class does not provide an `stream()` method, like the one provided by `org.hibernate.query.Query` class.

Why is this class not providing such method? Is there any chance of using streams with criteria?

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![gsmet](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/gsmet/32/9_2.png) [@gsmet](https://discourse.hibernate.org/u/gsmet)\
**Post date:** [August 3, 2018, 4:09pm UTC](https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144/2 "2018-08-03T16:09:26Z")

</div>

`CriteriaImpl` is an internal class so you shouldn’t extend it.

Considering the criteria API is deprecated in favor of the JPA criteria, I don’t see us making changes in it.

Note that I wouldn’t recommend to use the JPA criteria API directly as it’s barely usable but things like QueryDSL helps a lot.

---

<div class="post-metadata">

**Author:** ![vlad](https://yyz1.discourse-cdn.com/flex035/user_avatar/discourse.hibernate.org/vlad/32/658_2.png) [@vlad](https://discourse.hibernate.org/u/vlad)\
**Post date:** [August 7, 2018, 10:04am UTC](https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144/3 "2018-08-07T10:04:17Z")

</div>

If you use Criteria API, you can use the `stream` method either via JPA 2.2 `getStreamResult()` or if you unwrap the JPA `Query` to an `org.hibernate.query.Query` and call [`stream`](https://docs.jboss.org/hibernate/orm/5.2/javadocs/org/hibernate/query/Query.html#stream--).

However, just because you can, doesn’t mean you should. Most often, [pagination is a much better alternative to streaming](https://vladmihalcea.com/whats-new-in-jpa-2-2-stream-the-result-of-a-query-execution/).

---

<div class="post-metadata">

**Author:** ![caristu](https://avatars.discourse-cdn.com/v4/letter/c/85f322/32.png) [@caristu](https://discourse.hibernate.org/u/caristu)\
**Post date:** [August 8, 2018, 6:22am UTC](https://discourse.hibernate.org/t/how-to-call-stream-on-the-hibernate-criteriaimpl-object/1144/4 "2018-08-08T06:22:34Z")

</div>

Hello,

ok, understood. Thank you very much @gsmet and @vlad for the information.
