Lambda to collect properties in a child object
First, you can use Stream.flatMap() to convert a Stream of ProductInvoice to ProductEntries.

Next, you just need suitable Collector implementations to sum all the quantities per product ID, and group by that...

Putting it all together:

Map&lt;Long, Long&gt; result = productInvoiceRepository
                            .findByProductEntries_ProductIdIn(productIds)
                            .stream().flatMap(v -&gt; v.getProductEntries().stream())
                            .collect(Collectors.groupingBy(ProductEntry::getProductId,
                                    Collectors.summingLong(ProductEntry::getQuantity)));


BTW, you may want to consider a better method name for findByProductEntries_ProductIdIn() to remove the underscore...