| My experiences with Stream are limited, not sure what'd be the best. Eagerly fetching all results into a list should be avoided, so the implementation of session.createQuery("from Event").stream() should be backed by scrollable results in one way or another. I.e. the following should not fetch all events but only so many to find the first matching one and then not consume the result iterator any more:
Optional<Event> event = session.createQuery("from Event")
.stream()
.filter(e -> e.getTitle == "Java 8")
.findFirst();
|