From the course: Java Persistence API (JPA): 2 Inheritance and Querying

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Query using streams

Query using streams

From the course: Java Persistence API (JPA): 2 Inheritance and Querying

Start my 1-month free trial

Query using streams

- [Instructor] The Stream API can be used to process results of database queries. We will also discuss what developers should consider when using streams. JPA 2.2 introduced several new features, and one of them is the new getResultStream method. The method is now part of the query interface, and returns a Java h stream of the query results. 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. As we've already seen, queries can be defined statically or dynamically. So when using JPA 2.2, you call the getResultStream method instead of the getResultList method. The rest of the API hasn't changed, so you can create the query as you did in JPA 2.1. Streaming query results was added because reading large datasets causes the entire result set to be pulled into memory before being used. In the past, developers worked around this by paging through the…

Contents