-->
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.  [ 5 posts ] 
Author Message
 Post subject: Translate HQL to Criteria
PostPosted: Wed Jun 20, 2007 7:28 am 
Newbie

Joined: Wed Jun 20, 2007 7:20 am
Posts: 5
Hi I am doing a complex search following the example of Ayende's Blog at this address

http://www.ayende.com/Blog/archive/2006/12/07/7055.aspx

Unfurtunately I couldn't find how to sum the multiplication of 2 columns with Criteria.
My HQL (just an abstract) is

select distinct c
from Customer c
where
(
select sum(d1.UnitPrice*d1.Quantity)
from Customer c1
join c1.Orders o1
join o1.Detail d1
where o1.Customer.Id = c.Id
) > 10000

How can I translate the above HQL it to Criteria?

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 3:50 am 
Newbie

Joined: Wed Jun 20, 2007 7:20 am
Posts: 5
Can anyone help me?


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 2:17 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
I haven't tried this, but have you checked out the docs on Projections (Section 12.7) and Projections.SqlProjection()? That would seem to be the place to start.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 6:13 pm 
Newbie

Joined: Wed Jun 20, 2007 7:20 am
Posts: 5
I read it on the reference.....but there is nothing about sum of multiplication.....

....any other suggestion? :)

thank you


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jun 26, 2007 11:25 pm 
Expert
Expert

Joined: Fri May 13, 2005 11:13 am
Posts: 292
Location: Rochester, NY
Unless I'm mistaken SqlProjection was included in the API so you could compose your own projection from an SQL string in complex situations like these. E.g.,

Code:
Projections.SqlProjection( "sum( d1.UnitPrice * d1.Quantity )", ... );


Not sure how all the subquery correlation works, but that seems to be covered elsewhere.


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