I've 2 entites:
class Parent {
Integer id;
List<Child> children;
}
class Child {
Integer id;
Parent parent;
}
In my DB query I'm fetching a list of Parents.
Now I want to group this list by Child IDs, i.e.
Map<Integer, List<Parent>> myMap;
Using Java 8's grouping by how can I do this?
Right now I'm using resultList.stream().collect(groupingBy(Parent::getChildren)), but this creates Map<Set<Child>, List<Parent>>, which is not what I'm looking for.