-->
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.  [ 1 post ] 
Author Message
 Post subject: Criteria API: Sub Criteria Returning Multiple columns
PostPosted: Wed Mar 14, 2007 7:43 am 
Newbie

Joined: Thu Feb 15, 2007 10:09 am
Posts: 4
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


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

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.