I think the right way to do this is to merge both findAllByAttributes() methods into a single join/group query that performs the aggregation, otherwise performance could be an issue.