By David Delabassee-Oracle on Jul 07, 2015
Retrieving a large, i.e. a very large, dataset using JPA might be
tricky as the whole result set has to fit within a java.util.List
instance. So a very large data set might potentially hit the memory
limits of the sever the application is running on.
For those scenarios with (very) large result set, pagination can be
used to work-around that limitation. See for example this "How To
Stream/Serialize JPA Result As JAX-RS Response For Large Data"
article. But for those scenarios, the Java 8 Streams API would also be a
good fit! Unfortunately, Streams are not supported in the current
release of JPA (JPA 2.1 - JSR 338) as it predates Java SE 8. But
this is clearly a potential RFE for the next update of JPA (see this specification RFE here).
In addition, some of the JPA implementations have already started to
add support for Java 8 Streams (e.g. Hibernate and EclipseLink).
We will have to wait a bit more to see what the scope of 'JPA.next' will be. What do you think? Would you like to see Java SE 8 Streams supported in 'JPA.Next'?