-->
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 SubSeclect to criteria
PostPosted: Tue Aug 09, 2005 9:59 am 
Senior
Senior

Joined: Tue Jan 11, 2005 5:03 pm
Posts: 137
Location: Montreal, Quebec
Hi,

Does anyone know how to translate this HQL in criteria?

from AstExchangeRate rate where rate.id.astRateDate = (select max(rate.id.astRateDate) from rate

Thanks

Etienne


Top
 Profile  
 
 Post subject: Re: HQL SubSeclect to criteria
PostPosted: Tue Aug 09, 2005 11:11 am 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
etienne wrote:
Hi,

Does anyone know how to translate this HQL in criteria?

from AstExchangeRate rate where rate.id.astRateDate = (select max(rate.id.astRateDate) from rate


Something like this:

Code:
DetachedCriteria maxRateDateQuery = DetachedCriteria.forClass(AstExchangeRate.class);
maxRateDateQuery.setProjection(Projections.max("id.astRateDate"));

Criteria rateQuery = session.createCriteria(AstExchangeRate.class);
rateQuery.add( Subqueries.eq("id.astRateDate",maxRateDateQuery) );

rateQuery.list();


Top
 Profile  
 
 Post subject:
PostPosted: Tue Aug 09, 2005 11:14 am 
Regular
Regular

Joined: Thu Dec 02, 2004 7:11 am
Posts: 85
Correction:

Code:
rateQuery.add( Subqueries.propertyEq("id.astRateDate",maxRateDateQuery) );


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.