title: org.hibernate.PropertyNotFoundException: Could not find setter for 0
body: <p>I'm fetching only selected attributes from a table using HQL, maintaining a list of non-entity class objects.
  For Eg. My entity class:</p>
  
  <pre><code>@Entity
  @Table(name="STUDENT")
  public class Student {
      @Id
      @GeneratedValue(strategy=GenerationType.IDENTITY)
      private Long id;
  
      @Column(name="NAME", columnDefinition="TEXT", length="60", nullable = false)
      private String name;
  
      @ManyToOne
      @JoinColumn(name = "Dept_id", nullable = false)
      private Department department;
  
      // Other fields...
      // Getter-Setters
  }
  </code></pre>
  
  <p>and non-persistent DTO class is having only fewer class members (say, name only):</p>
  
  <pre><code>public class StudentDTO {
      private String name;
      // Getter-Setter for name
  }
  </code></pre>
  
  <p>Now using</p>
  
  <pre><code>public List&lt;StudentDTO&gt; getStudents(Long deptId) {
      List&lt;StudentDTO&gt; students;
  
      Query query = session.createQuery("select student.name " +
              "from Student as student " +
              "where Dept_id =?").setResultTransformer(new AliasToBeanResultTransformer(StudentDTO.class));
      query.setString(0, Long.toString(deptId));
  
      students = CommonUtil.castList(StudentDTO.class, query.list()); 
      return students;
  }
  </code></pre>
  
  <p>where castList converts any collection into ArrayList.</p>
  
  <pre><code>public static &lt;T&gt; List&lt;T&gt; castList(Class&lt;? extends T&gt; clazz, Collection&lt;?&gt; c) {
              List&lt;T&gt; resultList = new ArrayList&lt;T&gt;(c.size());
              for(Object o: c)
                resultList.add(clazz.cast(o));
              return resultList;
          }
  </code></pre>
  
  <p>throws <strong>org.hibernate.PropertyNotFoundException: Could not find setter for 0 on class ../StudentDTO</strong></p>
  
  <p>Referring <a href="https://stackoverflow.com/questions/13834777/hibernate-exception-propertynotfoundexception-when-using-transformer">Hibernate exception PropertyNotFoundException when using Transformer</a>, I changed my query to <code>"select student.id as id,..."</code>, having <code>Long id</code> inside <code>StudentDTO</code> but that throw same exception, saying setter not found for 1.</p>
  
  <p>Getter/Setters are given for each property. Please suggest changes!</p>