title: Hibernate 4.1 Count Projection Type Mismatch (Long/Integer) using Result Transformer
body: <p>I have an entity bean <code>FooEntity</code> and DAO method to get row counts grouped by a property on that entity, encapsulated in a view model bean <code>FooCount</code>.</p>
  
  <pre><code>public List&lt;FooCount&gt; groupByFoo() {
      return sessionFactory.getCurrentSession()
          .createCriteria(FooEntity.class)
          .setProjection(Projections.projectionList()
              .add(Projections.groupProperty("foo"), "foo")
              .add(Projections.count("foo"), "count")
          ).setResultTransformer(Transformers.aliasToBean(FooCount.class))  
          .list();
  }
  
  public class FooCount {
      private String foo;
      private Integer count; // &lt;-- this is the problem
      // getters/setters...
  }
  </code></pre>
  
  <p>Running this gives an exception, since <code>Projections.count()</code> yields a <code>Long</code> instead of an <code>Integer</code>.</p>
  
  <pre><code>org.hibernate.PropertyAccessException: IllegalArgumentException occurred while calling setter of FooCount.count
      at org.hibernate.property.BasicPropertyAccessor$BasicSetter.set(BasicPropertyAccessor.java:119)
  --snip--
      Caused by: java.lang.IllegalArgumentException: argument type mismatch
  </code></pre>
  
  <p>It works if I change <code>count</code> to a <code>Long</code> but I would prefer not to change the view model class as it is used is various other places.</p>
  
  <p>Can I either make <code>Projections.count()</code> return an <code>Integer</code> somehow <em>or</em> make the result transformer convert from <code>Long</code> to <code>Integer</code>?</p>