-->
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: get values with max id
PostPosted: Mon Aug 01, 2011 6:26 am 
Newbie

Joined: Thu Jun 30, 2011 4:28 am
Posts: 2
hi all,

I'm trying to retrieve of some hotels from the database with max(id).
say the table is as follows:

Id Hotel Year Month values
1 3 2010 5 8
2 2 2010 6 10
3 4 2011 8 20
4 3 2011 3 16
5 1 2011 4 15
6 4 2011 8 23
7 3 2011 3 31

So lets say i want to get details of the hotels 3 and 4 where year = 2011 and month = 3 and 4 respectively.
for queries, hotel no. is given.

so the result set would be:
ID hotel year month values
for hotel 3, out of 2 records : 7 3 2011 3 31
hotel 4, out of 2 records : 6 4 2011 8 23

following is the code i used:

Criteria criteria = session.createCriteria(cls);
criteria.setProjection( Projections.max("decisionID") )
.add( Restrictions.like("year", year))
.add(Restrictions.like("month", month));

hotelList = criteria.list();

but this returns an empty list.
note that ID is not given.

could anyone please explain what is wrong in this code.

thanks in advance.


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.