title: Java Hibernate NamedQuery resultTransformer
body: <p>i have this query with <code>NamedQuery</code> using <code>Hibernate</code> this is my sample code.</p>
  
  <p><code>NamedQuery</code></p>
  
  <pre><code>@NamedQuery(name="com.company.generic.model.Student.getByID()",query="select name from com.company.generic.model.Student where id=:id")
  </code></pre>
  
  <p><code>Java Code</code></p>
  
  <pre><code>private Student getStudentNameById(Integer id)
  {
      final Session session = ....
      final Query query = session.getNamedQuery("com.company.generic.model.Student.getByID()")
      .setParameter("id",id)
      .setResultTransformer(Transformers.aliasToBean(Student.class));
      final Student student = (Student)query.uniqueResult();
      return student;
  }
  </code></pre>
  
  <p>when the query returns all the columns the <code>resultTransformer</code>works OK but when i return only a few columns returns </p>
  
  <pre><code>Exception in thread "main" org.hibernate.PropertyNotFoundException: Could not find setter for 0 on class com.company.generic.model.Student
  </code></pre>
  
  <p>my questions are</p>
  
  <p>1). why works with all columns but not working with a few or only a column.</p>
  
  <p>2). which is the diff between namedQuery and Criteria using resultTransformer should namedQuery have setProjection?</p>
  
  <p>3). must i write my own transformer? any workaround...? </p>
  
  <p>thanks a lot...</p>