-->
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.  [ 2 posts ] 
Author Message
 Post subject: Help converting HQL to Criteria
PostPosted: Thu Nov 29, 2007 8:17 am 
Newbie

Joined: Sun Oct 16, 2005 3:14 pm
Posts: 9
Location: Israel
Hibernate version: 3.0.2
Name and version of the database you are using: MySQL 5

I need help converting the below HQL to Criteria:

Code:
from BalanceItem i
where i.accountItem = :account and
      i.date = (select max(i2.date)
                from BalanceItem i2
                where i2.accountItem = :account and
                i2.date < :date)


Thanks in advance,

_________________
Hanan

Please don't forget to give credit if/when you get helpful information.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Dec 01, 2007 5:13 am 
Newbie

Joined: Sun Oct 16, 2005 3:14 pm
Posts: 9
Location: Israel
I found the answer and I am posting it here in case someone else will need it:

Code:
    DetachedCriteria tMaxDate = DetachedCriteria.forClass(BalanceItem.class).setProjection(Property.forName("date").max()).
            add(Restrictions.eq("accountItem", pAccountItem)).add(Restrictions.lt("date", pDate));
    return (BalanceItem)getCurrentSession().createCriteria(BalanceItem.class).add(Restrictions.eq("accountItem", pAccountItem)).
            add(Property.forName("date").eq(tMaxDate)).uniqueResult();

_________________
Hanan

Please don't forget to give credit if/when you get helpful information.


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