Reputation: 55
I was trying to get the repeated movies on the catalog.
In the catalog I have the id of the movies.
CatalogDaoImpl.class
@SuppressWarnings({ "unchecked" })
@Override
@Transactional
public List<Movie> findMovies() {
String query = "SELECT m.movie.id, count(m.movie.id)"
+ " from Catalog m group by m.movie.id"
+ " order by count(m.movie.id)";
List<Movie> movies = getSession().createQuery(query).getResultList();
return movies;
}
When I try to use this dao, I get the next error:
[Request processing failed; nested exception is java.lang.ClassCastException:
[Ljava.lang.Object; cannot be cast to com.myapp.entities.Movie]
Upvotes: 1
Views: 3669
Reputation: 16131
The error is because you declared the methods return type as List<Movie>
but de facto you are quyering a list of List<Object[]>
. This is because in your SELECT
clause you specified m.movie.id, count(m.movie.id)
.
If you want Movie
objects you should SELECT m.movie
...
Upvotes: 1