Join the Stack Overflow Community
Stack Overflow is a community of 6.8 million programmers, just like you, helping each other.
Join them; it only takes a minute:
Sign up
 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?

share|improve this question
up vote 11 down vote accepted

You forgot .list() at end of the query.

It should be something like

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

Refer hibernate documentation for more information.

share|improve this answer
    
Can You help get real List<Candidate>, now I get array of object, which consist of array of fields – user2645679 Aug 9 '13 at 14:39
    
@user2645679: You need to loop List<Object[]>, get Object[] and do lookup based on index, index 0 reporents first column data, index 1 represents second coulmns etc., populate that to Candidate Object. – Nambari Aug 9 '13 at 14:41
    
is there no better solution? – user2645679 Aug 9 '13 at 14:44
    
@user2645679: Not I know of when you are using native SQL. – Nambari Aug 9 '13 at 14:44
    
HQL can be helpfull for this situation? – user2645679 Aug 9 '13 at 14:45

Query not returning any thing and you are trying to assign it to 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();

A simple native query example

share|improve this answer
    
I think, you can help for write this query using HQL. I want to get List<Candidates> – user2645679 Aug 9 '13 at 15:04
    
Why query ,i would like suggest criteras..please have a look on criterias. – sᴜʀᴇsʜ ᴀᴛᴛᴀ Aug 9 '13 at 15:26

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.