Hi All,
I am using Hibernate 3.2.2.
I want to know how can I add two columns as In clause if my Sub-Criteria is returning 2 columns
For example I have a table called Student with following columns
StudentID, Name, Division, Marks
I want to get the topers from every division.
The SQL the query will something like
SELECT * FROM STUDENT WHERE (DIVISION, MARKS) IN
(SELECT DIVISION, MAX(MARKS) FROM STUDENT group by DIVISION)
Representation of this in Criteria API will be
Code:
public Collection<Student> findTopper() {
DetachedCriteria dc = DetachedCriteria.forClass(Student.class);
dc.setProjection(Projections.projectionList().
add(Projections.groupProperty("DIVISION"))
.add(Projections.property("MAX(MARKS)")));
//How do I add DIVISION and MARKS together as IN CLAUSE
Criteria c = getCurrSession().createCriteria(Student.class);
}
Thanks,
Sush