Spring JPA with collection count
<p>I am currently working on a project where I have given an entity <strong><code>Customer</code></strong> which has a collection of <strong><code>Order</code></strong> entities, hence a OneToMany relation between <strong><code>Customer</code></strong> and <strong><code>Order</code></strong>. Assuming that I want to select a subset of the <strong><code>Customer</code></strong> collection with the respective number of <strong><code>Order</code></strong> entities (in SQL known as <code>COUNT</code>): Isn't there already a default implementation for the query methods provided by Spring Data JPA to avoid writing a custom query with JPQL that fetches the number of orders by customer in one SQL-query instead of <em>n+1</em> queries where <em>n</em> is the number of customers? Or some kind of annotation that can be added in  <strong><code>Customer</code></strong> on some kind of transient field such as <code>long orderCount</code>?</p>