title: JPA Join Query(native query) custom dto
body: <p>Hi I am trying to join 3 table and fetch the collective result i.e dto using following query</p>
  
  <pre><code>SELECT f.id, u.email,
  count(distinct l.id) as likes_count,
  count(distinct c.id) as comments_count
  FROM feeds f 
  INNER JOIN users u ON f.user_id = u.id
  INNER JOIN likes l on l.feed_id = f.id 
  left join comments c on c.feed_id = f.id
  WHERE u.id = 12055
  group by f.id order by comments_count asc;
  </code></pre>
  
  <p>This query is working fine in mysql workbench, when i try to add this query to <code>@Query</code> annotation i am geeting <code>AbstractJpaQuery$TupleConverter$TupleBackedMap</code> exception, solution to this was to use <code>ContructorExpression</code> i added <code>new</code> expression but i am not getting it worked, my db entities are as below</p>
  
  <pre><code>@Entity
  @Table(name = "feeds")
  @NoArgsConstructor
  public class Feed {
  
      @Id
      @GeneratedValue(strategy = GenerationType.AUTO)
      @Getter
      @Setter
      Long id;
  
      @Getter
      @Setter
      @Column(columnDefinition = "TEXT")
      String content;
  
      public Feed(String content, User user) {
          this.content = content;
          this.user = user;
      }
  
      @ManyToOne(optional = false, cascade = CascadeType.ALL, fetch = FetchType.LAZY)
      @Getter
      @Setter
      User user;
  
  
      @OneToMany(mappedBy = "feed", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
      @Getter
      @Setter
      List&lt;Like&gt; likes;
  
  
      @OneToMany(mappedBy = "feed", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval = true)
      @Getter
      @Setter
      List&lt;Comment&gt; comments;
  
      @Override
      public String toString() {
          return "Feed{" +
                  "id=" + id +
                  ", user=" + user +
                  '}';
      }
  }
  </code></pre>
  
  <p>Custom DTO Object for above sql query:</p>
  
  <pre><code>@NoArgsConstructor
  @AllArgsConstructor
  public class FeedDetails {
  
      @Getter
      @Setter
      private Long id;
  
  
      @Getter
      @Setter
      private Long likes;
  
      @Getter
      @Setter
      private Long comments;
  
  
  }
  </code></pre>
  
  <p><code>Repository</code> method as below:</p>
  
  <pre><code>@Query("**sql_query**")
  List&lt;FeedDetails&gt; findAllFeedsByUserId(Long userId);
  </code></pre>
  
  <p>I am not sure what shout i write in <code>sql_query</code> such that i get proper <code>FeedDetails</code> <code>List</code> result.</p>