java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl 无法转换为 java.util.List 如何修复
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18148482/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl cannot be cast to java.util.List how to fix
提问by user2645679
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");
And I see:
我看到:
java.lang.ClassCastException: org.hibernate.internal.SQLQueryImpl cannot be cast to java.util.List
Query is correct. How to fix it?
查询正确。如何解决?
采纳答案by kosa
You forgot .list()
at end of the query.
您.list()
在查询结束时忘记了。
It should be something like
它应该是这样的
................skill.id where skill.id = 1").list();
Refer hibernate documentationfor more information.
有关更多信息,请参阅休眠文档。
回答by Suresh Atta
Query not returning any thing and you are trying to assign it to List
查询不返回任何内容,您正试图将其分配给 List
You should do
你应该做
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();