-->
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.  [ 3 posts ] 
Author Message
 Post subject: Arithmetic expressions in Select and using alias
PostPosted: Fri Mar 11, 2005 1:04 pm 
Newbie

Joined: Fri Mar 11, 2005 10:56 am
Posts: 2
Hi,

I am using Hibernate 2.1 and database PostgreSQL 7.4.

Does Hibernate support using arithmetic expressions in a HQL query ?

When using the following HQL:

select c.name, (c.cost1+c.cost2+c.cost3)
from Claimant c
order by totalcost

I get the following exception:
net.sf.hibernate.QueryException: aggregate function expected before ( aggregate function expected before ( in SELECT

What I actually need to do is the following:
select c.name, (c.cost1+c.cost2+c.cost3) as totalcost
from Claimant c
order by totalcost

(I need to add the values of three costs and assign it an alias
so that I can later order by this alias)

Can anyone help?

Thanks
Caron


Top
 Profile  
 
 Post subject: Derived property
PostPosted: Mon Aug 22, 2005 8:20 am 
Newbie

Joined: Fri Mar 11, 2005 10:56 am
Posts: 2
The answer is to use a derived property.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 22, 2005 8:34 am 
Expert
Expert

Joined: Thu Dec 04, 2003 12:36 pm
Posts: 275
Location: Bielefeld, Germany
Hibernate 3 supports arithmetic operators, I don't think Hibernate 2 does in this case.

Though, have you tried the following?
Code:
select c.name, sum(c.cost1+c.cost2+c.cost3)
from Claimant c

wresp.

Code:
select c.name
from Claimant c
order by sum(c.cost1+c.cost2+c.cost3)


I think this will work with Hibernate 2, but an alias for your aggregate function will probably only work with a recent version of Hibernate 3.

Best regards
Sven

_________________
Please don't forget to give credit, if this posting helped to solve your problem.


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