title: Count rows using criteria and projection
body: <p>I'm trying to get number of rows for specified criteria using projection. The idea is to count all items whose owner from specified city.</p>
  
  <p>Entities structure looks like this:</p>
  
  <pre><code>@MappedSuperclass
  class BaseEntity implements Serializable {
      @Expose
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      Long id;
  }
  
  class Item extends BaseEntity{
      @ManyToOne
      @JoinColumn(name = 'owner_id')
      Owner owner;
  }
  
  class Owner extends BaseExntity{
      @ManyToOne
      @JoinColumn(name = "city_id")
      City city;
  }
  
  class City extends BaseExntity{
      @Column(name = "name")
      String name;
  }
  </code></pre>
  
  <p>To select data I use next code with hibernate criteria:</p>
  
  <pre><code>Criteria c = session.createCriteria(Item.class);
  
  //just select all instances that have cityId = 1
  c.createAlias("owner.city", "city");
  c.add(Restrictions.like("city.id", 1L));
  c.list(); //1st invocation, this works well
  
  //Trying to count instances that have cityId = 1
  ProjectionList properties = Projections.projectionList();
  properties.add(Projections.rowCount(), "count");
  
  c.setProjection(properties);
  c.list(); //2nd invocation, here I receive an exception - object not found: CITY1_.ID 
  </code></pre>
  
  <p>At second c.list() invocation sql query looks like:
  <em>Hibernate: select count(*) as y0_ from item this_ where city1_.id like ?</em></p>
  
  <p>And it's not clear for me why first c.list() invocation works well but when i'm trying to count rows with projection it doesn't work and throws <em>object not found: CITY1_.ID</em> </p>
  
  <p>Hibernate version is 4.3.4.Final</p>