title: Select with join into custom type
body: <p>I have entities that look like the following:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Entity
  @Data
  @NoArgsConstructor
  @AllArgsConstructor
  public class MyEntity {
      @Id
      private UUID id;
  
      @OneToMany(targetEntity = Relation.class, fetch = FetchType.EAGER)
      private List&lt;Relation&gt; relatedList;
  }
  
  @Entity
  @Data
  public class Relation {
      @Id
      private UUID id;
  }
  </code></pre>
  
  <p>In addition, I have another type:</p>
  
  <pre class="lang-java prettyprint-override"><code>@Data
  public class OtherType extends MyEntity {
      private String otherField;
  
      public OtherType(UUID id, List&lt;Relation&gt; relations, String otherField) {
          super(id, relations);
          this.otherField = otherField;
      }
  }
  </code></pre>
  
  <p>What I want to do now is to select the objects in the table of <code>MyEntity</code> together with some additional info (<code>otherField</code>) into an object of type <code>OtherType</code>:</p>
  
  <pre class="lang-sql prettyprint-override"><code>select e.id, e.relatedList, 'otherStuff' as otherField from MyEntity e
  </code></pre>
  
  <p>If I use this query with HQL, it converts <code>e.relatedList</code> to <code>. as col_x_x_</code>, which obviously is a syntax error. I was trying to use a native query, but that just says that OtherType is not an Entity. If I use a NamedNativeQuery with a resultSetMapping, it can't map a list of values to a Collection (<code>No dialect mapping for JDBC type 1111</code>). What I also tried is use the postgres <code>array_agg</code> function to get only an array of IDs for my relation, but that can't be mapped either. Is there any way to achieve this except defining a constructor in <code>OtherType</code> that accepts a single value instead of a list, doing an actual real SQL join (where every instance of <code>Relation</code> adds another <code>MyEntity</code> row), and mapping that afterwards?</p>