I'm trying to write a query in which I fetch child records for my aggregate root using leftJoin like this:
dslContext.select()
.from(PARENT)
.leftJoin(CHILD)
.on(CHILD.PARENT_ID.eq(PARENT.ID))
.stream()
My problem is that I need to use stream because there are a very big number of records but this way I can't use fetchGroups which I would normally use when I need parent-child records.
This is how I'd use fetchGroups:
dslContext.select()
.from(PARENT)
.leftJoin(CHILD)
.on(CHILD.PARENT_ID.eq(PARENT.ID))
.fetchGroups(Parent.class, Child.class)
which would create a nice Map<Parent, Child> for me.
I tried to collect using Collectors.groupingBy but it is not straightforward how to use it and the docs don't explain it either.
How can I fetch parent-child records in one go lazily?