Hi.
Suppose I have a class like that:
public class Student {
private String name;
private float grade1, grade2;
/* Omitted accessors and mutators, that is, get and sets for
attributes above*/
public float getAverageGrade(){
return (this.grade1+this.grade2)/2.0
}
}
And I want to retrieve from the database, only the students that have passed (whose average grade is greater than 5). Can I do something like that?
List studentsThatPassed = session.find("from Student as student where student.getAverageGrade()>5.0");
I have not found anything like that at Hibernate documentation. If this is not possible, how can this be achieved by other means? Of course, one solution is
List allStudents = session.find("from Student");
and then I scan all the list calculating the average grade and picking up only students with average grade greater than 5. But this is very inefficient.
Is there a solution which does not imply to retrieve all students from the database?
Thank you,
Finsals Collons
|