user2645679
user2645679

Reputation: 147

select an individual object from hql result

I write

List<Candidate> candidates = (List<Candidate>)session.createQuery("from Candidate as candidate  left outer join candidate.skills as skill    where skill.id ="+ 1).list();

I get List of objects, which consists of Candidate object and Skill Object

How can I get only Candidates List ?enter image description here

Upvotes: 0

Views: 145

Answers (3)

c.s.
c.s.

Reputation: 4816

I can't currently remember if this works from Candidate as candidate where candidate.skills.skill.id = ?.

If it doesn't, you can probably use:

select distinct candidate from Candidate as candidate left outer join candidate.skills as skill where skill.id = ?

Upvotes: 1

Hew Wolff
Hew Wolff

Reputation: 1509

I think you want just a "join", not a "left outer join".

As Wikipedia says, "The result of a left outer join (or simply left join) for table A and B always contains all records of the "left" table (A), even if the join-condition does not find any matching record in the "right" table (B)." In particular an outer join will pull in data from the skills table, which it sounds like you don't want.

Upvotes: 0

Juned Ahsan
Juned Ahsan

Reputation: 68715

Is it what you need?

for (Candidate candidate:candidates) {
    if(candidate instanceOf Candidate) {
        System.out.println("This is candidate obj : " + candidate.toString());
    }

}

Upvotes: 0

Related Questions