title: How to count distinct items on specific fields in QueryDSL
body: <p><em>Edit: it turns out that JPA can't express this. The solution was to rewrite in SQL.</em></p>
  
  <p>I'm using QueryDSL to perform an aggregate query on a JPA data set for reporting. I have no problem extracting the report data. For example:</p>
  
  <pre><code>...
  query = query.groupBy(QVehicle.vehicle.make, QVehicle.vehicle.model);
  return query.listDistinct(new QMakeModelReportData(
              QVehicle.vehicle.make, QVehicle.vehicle.model,
              QVehicle.vehicle.make.count()));
  </code></pre>
  
  <p>This produces a list of my DTO object, each of which contains a vehicle make, vehicle model, and the count of vehicles of that make model. Like this:</p>
  
  <pre><code>   Ford, Focus, 14
     Ford, Mondeo, 4
     Vauxhall, Astra, 4
  </code></pre>
  
  <p>But I can't work out the syntax to count the number of rows before I actually perform the query. The syntax I imagine is like this, which doesn't exist:</p>
  
  <pre><code>return query.countDistinct(QVehicle.vehicle.make, QVehicle.vehicle.model);
  </code></pre>
  
  <p>I've ended up with a rather inefficient option:</p>
  
  <pre><code>return query
      .listDistinct(QVehicle.vehicle.make, QVehicle.vehicle.model)
      .size();
  </code></pre>
  
  <p>Is there anything better?</p>