title: use a non-entity class as a result class for native query
body: <p>every example/tutorials on the net deals with entity classes, when it comes to stored procedures (functions), where the SP collects data only from this entity. While it is quite common, that we have a complex query involving multiple tables and we want to have back some columns. For this we have can use a function in postgresql with or without any parameters.</p>
  <p>I have this piece of code for calling such a function:</p>
  <pre><code>@Component
  public class CapPlanningItemPerCapGroupImpl implements CapPlanningItemPerCapGroupRepository {
      private final EntityManager em;
  
      public CapPlanningItemPerCapGroupImpl(EntityManager em) {
          this.em = em;
      }
  
      @Override
      public List&lt;CapPlanningItemPerCapGroup&gt; getCapPlanningItems(Long companyId, Long plantId, int year, Long costAccTypeId) {
          Session session = em.unwrap(Session.class);
          NativeQuery&lt;CapPlanningItemPerCapGroup&gt; query = session.createNativeQuery(
                  &quot;SELECT * FROM get_cap_planning_items(:year, :companyId, :plantId, :costAccTypeId)&quot;, CapPlanningItemPerCapGroup.class);
          query.setParameter(&quot;year&quot;, year);
          query.setParameter(&quot;companyId&quot;, companyId);
          query.setParameter(&quot;plantId&quot;, plantId);
          query.setParameter(&quot;costAccTypeId&quot;, costAccTypeId);
  
          return query.getResultList();
      }
  }
  </code></pre>
  <p>The <code>CapPlanningItemPerCapGroup</code> class isn't annotated with <code>@Entity</code>, since I don't want to store it as a datatable in the db. It's like a custom type. But with this setting, the above query fails, saying, that <code>CapPlanningItemPerCapGroup</code> is an unknown entity.</p>
  <p>If I remove this <code>CapPlanningItemPerCapGroup.class</code> from the query call, I get the result in postman, but of course without any field names, just the raw data.</p>
  <p>So, my question is: do I really need to convert the result list manually to the appr. class type, or is there any mapping automatism out of the box, where I don't have to list all the returned column names and types?</p>
  <p>Thanks.</p>