By the way, seems to me that you should do s/th like this:
Code:
public class Teacher {
private int id;
private School school;
}
public class School {
private int id;
private String name;
}
and if you have some particular school1 you could do
Code:
SELECT t FROM Teacher AS t
where t.school = :theschool
and set :theschool = school1
in this case, school has many teachers, not one and you have no joins at all.
ljin wrote:
Hi, this is probably a very easy question, but I somehow can't find any answer to it. I have the following two classes:
Code:
public class Teacher {
private int id;
}
public class School {
private int id;
private Teacher teacher;
private String name;
}
Now, I want to write a query that gets all teacher's ID in a particular school.
Code:
SELECT t.id FROM School AS s INNER JOIN s.teacher AS t
where s.name = ?
Now my question is this: why do I need to join with the Teacher table. Apparently, there is this teacherId column in the School table, so I don't really need to join with Teacher. But I don't know how to access this in HQL. If someone knows, please help. Thanks in advance.