Stream : Advantages of The Method
Stream : Advantages of The Method
Entities
Entities are the most common projection with Hibernate, and you
can use them in a Stream in any way you like.
www.thoughts-on-java.org
How to get query results as a Stream
Scalar Values
Up to now, scalar values were not a very popular projection because
it returns a List of Object[]. You then have to implement a loop to go
through all Object[]s and cast its elements to their specific types.
That gets a lot easier with Streams.
POJOs
POJOs or similar projections can be easily created with a constructor
expression, as you can see in the following code snippet.
Unfortunately, there seems to be a bug (HHH-11029) in Hibernate
5.2.2 so that these projections don’t work with Streams. Instead of
mapping the BookValues to Strings and writing them to the log file,
the following code snippet throws a ClassCastException.
www.thoughts-on-java.org