JPA 2.2 introduced several new features, and one of them is the new getResultStream() method. This method is now part of the Query interface. As you might guess from its name, it allows you to retrieve the result of your query as a Stream. The goal of this method is to provide an efficient way to move through a result set. In the best case, it allows you to scroll through the result set instead of fetching all records at once.
You can see a simple example using the new method here. You just call the getResultStream() method instead of the getResultList() method. The rest of the API didn’t change. So, you can create the query, set bind parameter values and limit the number of selected records in the same way as you did in JPA 2.1.
Stream<Author> authors = em.createQuery("SELECT a FROM Author a", Author.class).getResultStream();