Hi,
Consider there are 3 classes representing 3 database tables: Student, Course and StudentCourse(associative relationship).
The source code bellow returns all students from the associative table that conform to some restrictions (ommited for clarity)
Code:
Criteria criteria= session.createCriteria(StudentCourse.class);
criteria.createCriteria("student", "s");
criteria.createCriteria("course", c");
// add some restrictions on s and c
criteria.setProjection(Projections.distinct(Projections.projectionList().add(
Projections.property("student"))));
return criteria.list();
As I need to return the students from the association StudentCourse I'm using a projection here and it is working. The problem is that I need to order this projection based on the student name and I failed on all my attempts. Considering that the Student class has a name attribute, what I need to do to order the results based on this attribute?
Thanks in advance!