title: Can a JPA Query return results as a Java Map?
body: <p>We are currently building a <code>Map</code> manually based on the two fields that are returned by a named JPA query because JPA 2.1 only provides a <code>getResultList()</code> method:</p>
  
  <pre><code>@NamedQuery{name="myQuery",query="select c.name, c.number from Client c"}
  
  HashMap&lt;Long,String&gt; myMap = new HashMap&lt;Long,String&gt;();
  
  for(Client c: em.createNamedQuery("myQuery").getResultList() ){
       myMap.put(c.getNumber, c.getName);
  }
  </code></pre>
  
  <p>But, I feel like a custom mapper or similar would be more performant since this list could easily be 30,000+ results.</p>
  
  <p>Any ideas to build a Map without iterating manually.</p>
  
  <p>(I am using OpenJPA, not hibernate)</p>