0
 List<Candidate> candidates = (List<Candidate>) session.createSQLQuery("select candidate.* from candidate inner join candidate_skill on candidate.id = candidate_skill.candidate_id inner join skill on candidate_skill.skill_id = skill.id where skill.id = 1");       

我看到了:

 java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl cannot be cast to java.util.List

查询是正确的。如何解决?

4

2 回答 2

12

.list()您在查询结束时忘记了。

它应该是这样的

................skill.id where skill.id = 1").list();

有关更多信息,请参阅休眠文档

于 2013-08-09T14:02:17.970 回答
2

查询不返回任何东西,您正在尝试将其分配给 List

你应该做

 List<Candidate> candidates = (List<Candidate>) session.createSQLQuery
               ("select candidate.* from candidate inner join 
                    candidate_skill on candidate.id = candidate_skill.
                        candidate_id inner join skill on 
                  candidate_skill.skill_id = skill.id 
                                          where skill.id = 1").list();

一个简单的原生查询示例

于 2013-08-09T14:03:04.947 回答