-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: HQL Question
PostPosted: Mon May 10, 2004 7:40 pm 
Newbie

Joined: Sun Apr 25, 2004 9:52 pm
Posts: 3
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


Top
 Profile  
 
 Post subject:
PostPosted: Mon May 10, 2004 8:27 pm 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Map it as a formula property, then you can use it in the where clause. Or specify the formula explicitly in the where clause.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.