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");       

And I see:

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

Query is correct. How to fix it?

2 Answers 2

13

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.

Sign up to request clarification or add additional context in comments.

7 Comments

Can You help get real List<Candidate>, now I get array of object, which consist of array of fields
@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.
is there no better solution?
@user2645679: Not I know of when you are using native SQL.
HQL can be helpfull for this situation?
|
2

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

2 Comments

I think, you can help for write this query using HQL. I want to get List<Candidates>
Why query ,i would like suggest criteras..please have a look on criterias.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.