title: Projections.count() and Projections.countDistinct() both result in the same query
body: <p>EDIT: I've edited this post completely, so that the new description of my problem includes all the details and not only what I previously considered relevant. Maybe this new description will help to solve the problem I'm facing.</p>
  
  <p>I have two entity classes, Customer and CustomerGroup. The relation between customer and customer groups is ManyToMany. The customer groups are annotated in the following way in the Customer class.</p>
  
  <pre>
  <code>
  @Entity
  public class Customer {
    ...
    @ManyToMany(mappedBy = "customers", fetch = FetchType.LAZY)
    public Set&lt;CustomerGroup&gt; getCustomerGroups() {
      ...
    }
    ...
    public String getUuid() {
      return uuid;
    }
    ...
  }
  </code>
  </pre>
  
  <p>The customer reference in the customer groups class is annotated in the following way</p>
  
  <pre>
  <code>
  @Entity
  public class CustomerGroup {
    ...
    @ManyToMany
    public Set&lt;Customer&gt; getCustomers() {
      ...
    }
  
    ...
  
    public String getUuid() {
      return uuid;
    }
    ...
  }
  </code>
  </pre>
  
  <p>Note that both the CustomerGroup and Customer classes also have an UUID field. The UUID is a unique string (uniqueness is not forced in the datamodel, as you can see, it is handled as any other normal string).</p>
  
  <p>What I'm trying to do, is to fetch all customers which do not belong to any customer group OR the customer group is a "valid group". The validity of a customer group is defined with a list of valid UUIDs.</p>
  
  <p>I've created the following criteria query</p>
  
  <pre>
  <code>
  Criteria criteria = getSession().createCriteria(Customer.class);
  criteria.setProjection(Projections.countDistinct("uuid"));
  criteria = criteria.createCriteria("customerGroups", "groups", Criteria.LEFT_JOIN);
  
  List&lt;String&gt; uuids = getValidUUIDs();
  Criterion criterion = Restrictions.isNull("groups.uuid");
  if (uuids != null && uuids.size() &gt; 0) {
    criterion = Restrictions.or(criterion, Restrictions.in(
        "groups.uuid", uuids));
  }
  criteria.add(criterion);
  </code>
  </pre>
  
  <p>When executing the query, it will result in the following SQL query</p>
  
  <pre>
  <code>
  select
      count(*) as y0_ 
  from
      Customer this_ 
  left outer join
      CustomerGroup_Customer customergr3_ 
      on this_.id=customergr3_.customers_id 
  left outer join
      CustomerGroup groups1_ 
      on customergr3_.customerGroups_id=groups1_.id 
  where
      groups1_.uuid is null 
      or groups1_.uuid in (
          ?, ?
      )
  </code>
  </pre>    
  
  <p>The query is exactly what I wanted, but with one exception. Since a Customer can belong to multiple CustomerGroups, left joining the CustomerGroup will result in duplicated Customer objects. Hence the <code>count(*)</code> will give a false value, as it only counts how many results there are. I need to get the amount of unique customers and this I expected to achieve by using the <code>Projections.countDistinct("uuid");</code> -projection. For some reason, as you can see, the projection will still result in a <code>count(*)</code> query instead of the expected <code>count(distinct uuid)</code>. Replacing the projection <code>countDistinct</code> with just <code>count("uuid")</code> will result in the exactly same query.</p>
  
  <p>Am I doing something wrong or is this a bug?</p>
  
  <p>===</p>
  
  <p>"Problem" solved. Reason: PEBKAC (Problem Exists Between Keyboard And Chair). I had a branch in my code and didn't realize that the branch was executed. That branch used rowCount() instead of countDistinct().</p>