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: Complex Hibernate Query - TopGrossing/Selling Products
PostPosted: Wed Feb 01, 2012 5:26 am 
Newbie

Joined: Wed Feb 01, 2012 5:14 am
Posts: 1
I want to execute a complex query in Hibernate, but I am getting errors. I have a product_transaction table that stores all purchases related to a product, basically the transaction history.

I want to pull back all the top selling and top grossing products but the Hibernate SQL keeps throwing errors, I am inexperienced in complex queries and using methods such as criteria etc.

Any suggestions for reproducing these queries (these are in a ProductTransaction.hbm.xml file as a named query)?

select * , sum(amount) as totalsalesamount
from ProductTransaction pt
where pt.ownerUser=:ownerUserId
and pt.purchaseDate between :periodStartDate and :periodEndDate
group by pt.productId
order by totalsalesamount desc
limit :numResults

select *, count(*) sellingcnt
from ProductTransaction pt
where pt.ownerUser=:ownerUserId
and pt.purchaseDate between :periodStartDate and :periodEndDate
group by pt.productId
order by sellingcnt desc
limit :numResults


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.