title: Java 8 stream from a JPA Repository
body: <p>I would like to create a Stream from a JPA Repository. The goal is to map the Entities coming from the Repo (which could be more than a million) to other Entities which will in turn be stored in another Repo.</p>
  
  <p>So far I built a Collector which will collect a given number (e.g. 1000) Entities and then store them into the target Repo. This will work in a parallel Stream. What I need now is a good way to fetch Entities from the source Repo and feed them into the Stream as they are needed.</p>
  
  <p>Most promising so far was to implement a Supplier (<a href="http://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html" rel="nofollow">http://docs.oracle.com/javase/8/docs/api/java/util/function/Supplier.html</a>) to build the Stream via generate but I did not find a way to terminate the process when the query to the source Repo does not provide another Entity.</p>
  
  <p>Any pointers?</p>