title: Map Object Array to a Bean
body: <p>I am making an SQL query via JPA and getting a List of Object Arrays. I wish to map these Object Arrays into a bean. </p>
  
  <p>For example, my query gives me the following output.</p>
  
  <pre><code>List&lt;Object[]&gt; list = // myWorkingJpaQuery;
  // list is of length 2. 
  // Each Object array always holds a Long in index 0, 
  // a TimeStamp in index 1 and a String in index 2. 
  </code></pre>
  
  <p>Instead of reading these values and performing casting, I wish to map it to a class as follows: </p>
  
  <pre><code>class ExampleClass{
      //all these variables matches the aliases in myWorkingJpaQuery.
      Long id;
      TimeStamp ts;
      String name;
      // get set
  }  
  </code></pre>
  
  <p>Tried to use the above class my changing the JPA methods return type and assigning it in the calling class as follows but it doesn't work. </p>
  
  <pre><code>List&lt;ExampleClass&gt; list = // myWorkingJpaQuery with List&lt;ExampleClass&gt; as return type;
  </code></pre>
  
  <p>Is there a way to do this? It is currently working fine if I stick to Object Array but just trying not to use Objects and castings. For reference, I am using Spring.</p>