-->
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: One shot calculation query
PostPosted: Thu Jun 28, 2007 5:11 pm 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
Hi!

I have an HQL clause that read's successfully the following statement, but

Code:
SELECT OD.id, sum(PL._plannedAmount)
                    FROM PlanLines as PL                 
                    RIGHT JOIN PL._orderDetail as OD             
                    WHERE
                    OD._order=:order                     
                    GROUP BY OD.id



But this returns me an IList within array of int32, int32.

So after retrieving these items, I have to loop through the recived List and
one by one re-read OrderDetail from database.

Selecting the result as OD and calculation it won't work beacause GROUP BY Cannot handle OD. So I have to manually populate all the OD.properties :(

It would be nice if GROUP BY would accept OD.*

Code:
SELECT OD, sum(PL._plannedAmount)
                    FROM PlanLines as PL                 
                    RIGHT JOIN PL._orderDetail as OD             
                    WHERE
                    OD._order=:order                     
                    GROUP BY OD.*


But not only this produces invalid sql in GROUP BY section there is
something like OD.ID*

The perfect solution would be If I Could write something like this
Code:
SELECT OD, sum(PL._plannedAmount) as {OD.amount}
                    FROM PlanLines as PL                 
                    RIGHT JOIN PL._orderDetail as OD             
                    WHERE
                    OD._order=:order                     
                    GROUP BY OD.*


and the result would come List of OrderDetails and
OrderDetails.amount would be filled with sum or any other calculation value.




Thanks for reading this post!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 28, 2007 11:01 pm 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
Perhaps the 2 solutions in this old post may be useful to you. http://forum.hibernate.org/viewtopic.php?t=972214&start=0&postdays=0&postorder=asc&highlight=


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 4:26 am 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
It won't help, if you ment new OrderLine(od, sum(xxxx))

Beacause here is the issue when HQL in ORDER BY won't generate as many
fields as this object will request. And the syntax will brake the SQL

Another thing jira seems not working?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 29, 2007 6:14 am 
Regular
Regular

Joined: Tue Aug 08, 2006 4:28 am
Posts: 96
Location: Hong Kong
My bad. I overlooked the GROUP BY OD.*

NHibernate can't handle this currently.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jun 30, 2007 1:34 am 
Beginner
Beginner

Joined: Sun Oct 22, 2006 12:06 pm
Posts: 39
GROUP BY OD.*

Won't work either beacause as there is INNER JOIN FETCH it will generate more elements in sql than OD elements

So maybe GROUP BY * would be an idea, and it will generate as much elements as non aggregating SELECT statements.


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.