-->
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: Aggregate of a multiplication in NHibernate
PostPosted: Fri Sep 08, 2006 2:53 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Hi,

I'm having problems with aggregate queries. I'm using NHibernate 1.0.2.0

I have a HQL query which performs a SUM() of a multiplication; like this:

Code:
select sum (ol.NumberOfItems * ol.ArticlePrice) from ....


Now, in NHibernate, this doesn't work. The query is not correctly translated (at least not in the nhibernate version i'm using)

Then, I want to try to solve this using native SQL, via the CreateSQLQuery method.
However, this method takes 3 arguments: the SQL query, the alias and the type of the return-class.
Now, the problem is that I just want to return this simple decimal result. This does not map to any of my classes (it's just a primitive that I want to get), so, how do I do this ? What should I use as 3rd argument (the type of the return class) ?

Or, is there any other way to solve this, without to much performance loss ?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 3:13 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
Update,

I've just downloaded NHibernate 1.2.0 alpha, and my original problem (with the aggregate query) still exists.

The problem is this:

This is how my HQL looks like:

Code:
select sum (ol.NumberOfItems * ol.ArticlePrice)
from Order o,  OrderLine ol, Customer c " +
where ol.OwningOrder = o and o.OwningCustomer = c "
and c.Id = :custId and o.OrderDate >= :orderDate


NHibernate translates this HQL to the following SQL (only the interesting part is pasted here :) ):

Code:
select sum(orderline1_.NumberOfItems*orderline1_.ArticlePrice) as x0_0_ from ...


Then, NHibernate gives me an exception that says the field with the name x1_0_ cannot be retrieved.
Offcourse not, there is no field x1_0_. You -nhibernate- called it x0_0_ ...

This is very annoying. Now, I always have to work around this, and mostly it is not very performant.

So, I try to work around it using a native SQL query, but there, I'm stuck with this 3rd parameter... what should I give as 3rd parameter (classtype) when I do not want to return a mapped class ?

I've created a ticket for it a while ago...
http://jira.nhibernate.org/browse/NH-555


Top
 Profile  
 
 Post subject:
PostPosted: Fri Sep 08, 2006 4:51 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
You can use ADO.NET directly to run SQL returning simple values.

Also, I believe that the bug may be fixed in the current SVN already, but it would be good if you could supply a simple test case for it so I could verify it.


Top
 Profile  
 
 Post subject:
PostPosted: Sat Sep 09, 2006 3:39 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
sergey wrote:
You can use ADO.NET directly to run SQL returning simple values.

Also, I believe that the bug may be fixed in the current SVN already, but it would be good if you could supply a simple test case for it so I could verify it.
I've sent you an email with a link to a simple sample.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 14, 2006 1:33 pm 
Regular
Regular

Joined: Mon Aug 29, 2005 3:07 pm
Posts: 77
hmm, seems like I forgot to put some comment in my last post. :)

Anyway, I've sent you a simple example for this issue


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.