I'm working with Hibernate and this is my scenario:
I have two entities, without any relation between them (the only relations that exist are logic relations, and that's the problem).
The two entities are like Student and FinalExam.
Student and Exam are like that:
class Student {
private String name;
private String surname;
private int age;
}
class FinalExam {
private String candidateName;
private String candidatesurname;
private int mark;
}
I'd like to create an HQL query to have the following columns: name, surname, passed.
Name and surname are the name and surname of the Student, the connection between the 2 entities.
The column passed can be true or false. It represents if a Student has passed the exam.
So it is true if exists a row in FinalExam with a mark higher then 6.
How I can achieve that?
I'd like something like that:
select s.name, s.surname, ( Select count(*)>1 from FinalExam exam
where exam.name = s.name
and exam.surname = s.surname
and exam.mark > 6)
from Student s