title: JPA mapping native query result to non entity DTO
body: <p>I have a complex native query and I am trying to map its result to a non-entity DTO class. I am trying to use <code>JPA</code>'s <code>SqlResultSetMapping</code> with <code>ConstructorResult</code> </p>
  
  <p>My DTO class</p>
  
  <pre><code>@Data
  public class Dto {
  
      private Long id;
  
      private String serial;
  
      private Long entry;
  
      private int numOfTasks;
  }
  </code></pre>
  
  <p>My entity class, which has the repository interface that I will call this native query result.</p>
  
  <pre><code>@SqlResultSetMapping(
          name = "itemDetailsMapping",
          classes = {
                  @ConstructorResult(
                          targetClass = Dto.class,
                          columns = {
                                  @ColumnResult(name = "ID"),
                                  @ColumnResult(name = "SERIAL"),
                                  @ColumnResult(name = "ENTRY"),
                                  @ColumnResult(name = "TASKS")
                          }
                  )
          }
  )
  
  @NamedNativeQuery(name = "getItemDetails", query = "complex query is here", resultSetMapping = "itemDetailsMapping")
  @Entity
  @Data
  public class Item {}
  </code></pre>
  
  <p>Repository</p>
  
  <pre><code>@Repository
  public interface ItemRepository extends JpaRepository&lt;Item, Long&gt; {
  
      ...     
  
      List&lt;Dto&gt; getItemDetails();
  
  }
  </code></pre>
  
  <p>When I call the <code>getItemDetails()</code> from <code>ItemRepository</code> I have the following error:</p>
  
  <blockquote>
    <p>org.springframework.data.mapping.PropertyReferenceException: No
    property itemDetails found for type Item</p>
  </blockquote>
  
  <p>What is the proper way to use <code>SqlResultSetMapping</code> and <code>ConstructorResult</code>
  and solve this problem. </p>
  
  <p>Any help would be appreciated.</p>