title: Jpa Repository query - java.lang.Object; cannot be cast to model
body: <p><strong><code>Movie</code></strong> model :</p>
  
  <pre><code>@Entity
  public class Movie {
  
      private Long id;
      private String name;
      private Date releaseDate;
      private List&lt;MovieCelebrity&gt; movieCelebrities = new ArrayList&lt;&gt;();
  
      // getters &amp; setters
  }
  </code></pre>
  
  <p><strong><code>MovieCelebrity</code></strong> model :</p>
  
  <pre><code>@Entity
  public class MovieCelebrity extends DateAudit {
  
      private Long id;
      private String characterName;
      private Movie movie;
  
      // getters &amp; setters
  }
  </code></pre>
  
  <p>I want to return the <strong>id</strong>, <strong>name</strong>, <strong>releaseDate</strong> and <strong>characterName</strong> along in the response, something like this:</p>
  
  <pre><code>{
      "id": 1,
      "name": Scarface,
      "releaseDate": 1983,
      "characterName": "Tony Montana"
  }
  </code></pre>
  
  <p>So i made the following query:  </p>
  
  <pre><code>@Query("SELECT m.id, m.name, m.releaseDate, mc.characterName FROM Movie m JOIN m.movieCelebrities mc " +
         "WHERE mc.celebrity.id = :id AND mc.role = :role")
  Page&lt;Movie&gt; findMoviesByCelebrity(@Param("id") Long id, @Param("role") CelebrityRole role, Pageable pageable);
  </code></pre>
  
  <p>But I'm getting the following error in the response:  </p>
  
  <blockquote>
    <p>"java.base/[Ljava.lang.Object; cannot be cast to com.movies.mmdb.model.Movie"</p>
  </blockquote>
  
  <p>There's a solution to create a constructor in movie with the parameter i need to return and make a query like:  </p>
  
  <pre><code>@Query("SELECT new Movie(m.id, m.name, m.releaseDate, mc.characterName) FROM...)
  </code></pre>
  
  <p>But since <strong>characterName</strong> is in different model i can't make such a constructor.</p>