title: mapping list from JPA Query.getResultList() to a customized TO
body: <p>I have a table fruit with four columns id, name, color, shape.</p>
  
  <p>entries in the table would be:</p>
  
  <pre><code>1, apple, red, round
  2, banana, yellow, long
  3, tomato, red, round
  4, orange, orange, round
  </code></pre>
  
  <p>Now I made an entity class Fruit mapped to above table.</p>
  
  <pre><code>@Entity
  @Table(name="fruit")
  public class Fruit implements Serializable {
  
  @Id
  @Column(name="ID")
  String id;
  
  @Column(name="NAME")
  String name;
  
  @Column(name="COLOR")
  String color;
  
  @Column(name="SHAPE")
  String shape;
  
  //getters/setters goes here
  }
  </code></pre>
  
  <p>In my DAO class, the code is:</p>
  
  <pre><code>String myQuery = "Select f.shape, f.name from Fruit f where f.shape = :shape";
  Query query = this.em.createQuery(myQuery);
  query.setParameter("shape", "round");
  </code></pre>
  
  <p>As obvious, running above query will return 3 rows. </p>
  
  <p>I have a simple TO class FruitSearchTO</p>
  
  <pre><code>class FruitSearchTO
  {
    String shape;
    String name;
  
    //getters/setters here
  }
  </code></pre>
  
  <p>This TO complies with the rows returned by my query.</p>
  
  <p>But in my DAO running something like:</p>
  
  <pre><code>List&lt;FruitSearchTO&gt; fruitList = new ArrayList&lt;FruitSearchTO&gt;();  
  fruitList = query.getResultList();
  </code></pre>
  
  <p>is throwing exception java.lang.ClassCastException: [Ljava.lang.Object; incompatible with FruitSearchTO]</p>
  
  <p>Where am I going wrong and what is the solution to this ?</p>