title: Native Query returns list with java.lang.Object instead of custom object type in JPA application
body: <p>I have the following tables in my MySQL database:</p>
  
  <pre><code>Student
  id | firstName | lastName | ...
  
  Course
  id | name | cp | ...
  -
  
  CourseResult (course_id and student_id are created by JPA)
  id | course_id | student_id | grade | ...
  -
  </code></pre>
  
  <p>I am trying to work with all <code>Students</code> who are in a <code>Course</code> defined by a given <code>course_id</code>. For that I've created a method in my controller:</p>
  
  <pre><code>public String showCourseResultList(Course course) {
      this.course = course;
      studentsInCourse = new ArrayList&lt;Student&gt;();
      studentsInCourse = em
              .createNativeQuery(
                      "SELECT * FROM Student WHERE id IN (SELECT student_id FROM CourseResult WHERE course_id = ?)")
              .setParameter(1, course.getId()).getResultList();
      System.out.println(studentsInCourse);
      return "courseResultList?faces-redirect=true";
  }
  </code></pre>
  
  <p>So in the NativeQuery I am detecting all <code>student_ids</code> for a given <code>course_id</code>. Then I use the <code>student_ids</code> to select all <code>Students</code> from the <code>Student</code> table.
  In other words I want to collect all <code>Students</code> in an <code>ArrayList&lt;Student&gt;</code>, who are in the given <code>Course</code>.</p>
  
  <p>The problem is, that after doing that, the <code>ArrayList&lt;T&gt;</code> contains elements from the type <code>java.lang.Object</code> instead of my custom type <code>Student</code>.
  The <code>System.out.println(studentsInCourse);</code> returns <code>[[Ljava.lang.Object;@3adaf419, [Ljava.lang.Object;@7ccfb37e]</code>.</p>
  
  <p>How can I collect all the <code>Students</code> from type <code>Student</code> in my <code>ArrayList&lt;T&gt;</code> instead of <code>ArrayList&lt;java.lang.Object&gt;</code>?</p>