-->
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.  [ 3 posts ] 
Author Message
 Post subject: HQL select question
PostPosted: Thu Sep 08, 2005 5:22 am 
Newbie

Joined: Fri Jul 30, 2004 9:02 am
Posts: 9
Location: Ukraine
Hibernate version: 2
Hi,
Have a problem with selecting using HQL,
model:
Code:
class Accomodation {
     Employee employee ;
     Calendar date;
}

I need to get all Accomodations where for every employee is the latest date;
example: if there are two accomodation for one employee it should be one with the latest date.
So, seems that accomodations should be grouped by employee, but how to select the most latest records I don't know.

_________________
--
Let's do a life easier


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:27 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
criteria should do it

Code:
Criteria crit = session.createCriteria(Accomodation.class);
crit.addOrder(Order.asc("date"));  //or descending, i can never remember
crit.setMaxResults(1);
Accomodation acc = (Accomodation) crit.list.iterator().next();


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 08, 2005 10:29 am 
Expert
Expert

Joined: Fri Aug 19, 2005 2:11 pm
Posts: 628
Location: Cincinnati
you can add more criteria to specify which employee to run it on also :)


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 3 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.