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
查询是正确的。如何解决?
答案 0 :(得分:12)
您在查询结束时忘记了.list()
。
应该是
................skill.id where skill.id = 1").list();
有关详细信息,请参阅hibernate documentation。
答案 1 :(得分:2)
查询不返回任何内容,并且您尝试将其分配给列表
你应该做
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();