title: JPA 2.0 Native Query Result Mapping to a Bean
body: <p>I have a complex Native Query. So using JPA 2.0 (with Hibernate implementation),  I have declared a NamedNativeQuery</p>
  
  <pre><code>@NamedNativeQuery(name="latestStatusByUser",
              query=" with latest_behav_status as "
                      + " (select .......),"
                      + " latest_behav_avail as ("
                      + " .......) "
                      + " select ........"                        
                      + " from user "
                      + " left outer join latest_behav_status lbs .... "
                      + " left outer join...."
  </code></pre>
  
  <p>So In my code I call:</p>
  
  <pre><code>List&lt;UserBehavior&gt; rec = entityManager.createNamedQuery("latestStatusByUser").getResultList();
  </code></pre>
  
  <p>But, as Result, I get a List of Object instead of List of UserBehavior. Even if I specify the result class, I get Error as UserBehavior is a POJO and not an Entity.</p>
  
  <p>Using named Query, I new that I can use :</p>
  
  <pre><code> select new org.project.UserBehavior(user_i...) from
  </code></pre>
  
  <p>But How to do with a NativeQuery and with JPA2.0 (JPA2.1 come with a solution, using @ConstructorResult):</p>
  
  <p><a href="http://mariemjabloun.blogspot.com/2014/05/jpa-mapping-native-query-to-bean-pojo.html" rel="nofollow">http://mariemjabloun.blogspot.com/2014/05/jpa-mapping-native-query-to-bean-pojo.html</a></p>
  
  <p>So the Question is how to map the resultset into a Bean using JPA 2.0??</p>