title: How to map the result set of a JPA NativeQuery to a POJO using SqlResultSetMapping
body: <p>I am attempting to map the results of a Native query to a POJO using @SqlResultSetMapping with @ConstructorResult.  Here is my code:</p>
  
  <pre><code>@SqlResultSetMapping(name="foo",
      classes = {
          @ConstructorResult(
                  targetClass = Bar.class,
                  columns = {
                      @ColumnResult(name = "barId", type = Long.class),
                      @ColumnResult(name = "barName", type = String.class),
                      @ColumnResult(name = "barTotal", type = Long.class)
                  })
      })
  
  public class Bar {
  
  private Long barId;
  private String barName;
  private Long barTotal;
  
  ...
  </code></pre>
  
  <p>And then in my DAO:</p>
  
  <pre><code>Query query = em.createNativeQueryBar(QUERY, "foo");
  ... set some parameters ...
  List&lt;Bar&gt; list = (List&lt;Bar&gt;) query.getResultList();
  </code></pre>
  
  <p>I have read that this functionality is only supported in JPA 2.1, but that is what I am using.  Here's my dependency:</p>
  
  <pre><code>        &lt;dependency&gt;
              &lt;groupId&gt;org.hibernate.javax.persistence&lt;/groupId&gt;
              &lt;artifactId&gt;hibernate-jpa-2.1-api&lt;/artifactId&gt;
              &lt;version&gt;1.0.0.Final&lt;/version&gt;
          &lt;/dependency&gt;
  </code></pre>
  
  <p>I found a couple of resources, including this one: <a href="https://stackoverflow.com/questions/22423604/constructorresult-mapping-in-jpa-2-1">@ConstructorResult mapping in jpa 2.1</a>.  But I am still not having any luck.</p>
  
  <p>What am I missing?  Why can't the SqlResultSetMapping be found?</p>
  
  <pre><code>javax.persistence.PersistenceException: org.hibernate.MappingException: Unknown SqlResultSetMapping [foo]
  </code></pre>