Trying to get all articles, with unique titles (distinct(title)), that have a body of "".
List<Article> articles = (List<Article>) session.createQuery("select distin开发者_如何转开发ct a.title from Article a where body = :body")
.setString("body", "")
.list();
I am getting the error:
main java.lang.ClassCastException: java.lang.String cannot be cast to blah.Model.Article Exception in thread "main" java.lang.ExceptionInInitializerError
The Article table has duplicates in it, that is why I am trying to get only unique articles. It doesn't matter which once it gets, as long as the title is unique, and the body is "".
Update Could I use a subquery to get the results?
You're selecting the titles, not the articles - which is why you're getting strings back.
The query of "articles with distinct titles" doesn't even make sense - if you have two articles which share a title, which would you expect to be returned?
精彩评论