Query results as a Stream with Hibernate 5.2

Viewed 8536

Since Hibernate 5.2, we are able to use the stream() method instead of scroll() if we want to fetch large amount of data.

However, when using scroll() with ScrollableResults we are able to a hook into the retrieval process and to free memory up by either evicting the object from the persistent context after processing it and/or clearing the entire session every now and then.

My questions:

  1. Now, if we use the stream() method, what happens behind the scenes?
  2. Is it possible to evict object from the persistent context?
  3. Is the session cleared periodically?
  4. How is optimal memory consumption achieved?
  5. Is is possible to use e.g. StatelessSession?
  6. Also, if we have set hibernate.jdbc.fetch_size to some number (e.g. 1000) at JPA properties, then how is this combined well with scrollable results?
2 Answers
Related