title: JPA Typed Search Queries
body: <p>I have a rather big model Applicant:</p>
  
  <pre><code>public class Applicant{
   private Long id
   private String name;
   ...
   ...
  }
  </code></pre>
  
  <p>To populate a selection list, I need a list of (id, name) tuples and I use this search query:   </p>
  
  <pre><code>public List getNames() {
      Query query = em.createQuery("select a.id, a.name from Applicant a");
      return query.getResultList();
  
  }
  </code></pre>
  
  <p>However, I get a list of Object[]'s and I don't really want to convert these in the business layer to the corresponding types (Long and String). What is the best way to approach this? Should I iterate through the list and manually do the type conversion before returning it? Or should I make a helper class:</p>
  
  <pre><code>public class ApplicantTuple{
   public Long id
   public String name;
  
   public Application(Long id, String name) {
      ...
   }
  
  }
  </code></pre>
  
  <p>and then have a search query:</p>
  
  <pre><code>Query query = em.createQuery("select NEW my.model.ApplicantTuple(a.id, a.name) from Applicant a");
  </code></pre>
  
  <p>Or is there a better way to type search queries?</p>