Hi
I have 2 java classes: Media and Vote and a OneToMany association
Media has a Set of vote
Vote has a note (integer) as an attribute
I have a calculated method which sum all of notes of my media
Code:
public class Media {
....
private Set votes = new HashSet();
...
public int getEtoiles() {
int total = 0;
for (Iterator iterator = votes.iterator(); iterator.hasNext();) {
Vote vote = (Vote) iterator.next();
Integer note = vote.getNote();
total += note.intValue();
}
return total;
}
}
Code:
public class Vote {
private Long id;
private Integer note;
}
I want to get all medias sorted by the result of my method getEtoiles().
Any ideas to do this with a HQL query ? (with Criteria)
(I think I can use the sum method but I don't know how to do this)
Thanks for your help.