title: Spring-boot : Return custom pojo object with HQL
body: <p>Say I have these 3 entities</p>
  
  <pre><code>@Entity
  public class Student {
    @Id
    @Column
    long studentId;
  
    @Column
    String name;
  }
  
  
  @Entity
  public class Exam{
    @Id
    @Column
    long examId;
  }
  
  @Entity
  public class StudentExam {
    @Id
    @Column
    long studentExamId;
  
    @ManyToOne
    @JoinColumn("student_id")
    Student student;
  
    @ManyToOne
    @JoinColumn("exam_id")
    Exam exam;
  
    @Column
    int score;
  }
  </code></pre>
  
  <p>And I have this pojo class </p>
  
  <pre><code>public class StudentExamDTO {
    ExamDTO exam;
    StudentDTO student;
    int bestScore;
  }
  </code></pre>
  
  <p>Where ExamDTO and StudentDTO are simple non entities models. And best score is the best a student has obtained in the given exam.<br>
  What I want is a simple request to return directly the ExamStudentDTO using Spring-Boot repository interface </p>
  
  <pre><code>public interface ExamRepository extends JpaRepository&lt;ExamStudent, Long&gt; {
  
    @Query("select new StudentExam(...)  ..")
    Object getStudentExam(@Param("examId")long examId, @Param("studentId")long studentId);
  
  }
  </code></pre>
  
  <p>Is there a way I can access the data like doing Object["column"] ? If so, is it possible to fetch the result directly on the StudentExamDTO class ?</p>