-->
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: Sum of products
PostPosted: Thu Dec 18, 2003 4:39 am 
Newbie

Joined: Thu Dec 18, 2003 4:09 am
Posts: 3
I have the following query :

String q = "select tmarche.lbrm,"
+ " sum(tperfql.mtvtettc), sum(tperfql.mtvtettcm1),"
+ " sum(tperfql.mtmmav), sum(tperfql.mtmmar),"
+ " sum(tperfql.mtvteht)"
+ " from Tmarche as tmarche, Tperfql as tperfql,"
+ " Trespsb as trespsb, Tctscat as tctscat"
+ " where tmarche.cdrm = trespsb.comp_id.cdrm"
+ " and trespsb.comp_id.cdcat = tctscat.comp_id.cdcat"
+ " and tctscat.comp_id.cdscat = tperfql.comp_id.cdscat"
+ " and tperfql.comp_id.cdensg = :idEnseigne"
+ " group by tmarche.lbrm"
+ " order by sum(tperfql.mtvtettc) desc";

I used middlegen to get the mapping and it currently lacks table relationships, which makes the query quite verbose. However, it performs ok up to this point.

Now I need an other sum in my select clause :
+ " sum(tperfql.mtvteht * tobjtcm.txevvtettcp1),"
so I add in the from clause :
+ " Tobjtcm astobjtcm,"
and in the where clause :
+ " and tobjtcm.comp_id.cdscat = tperfql.comp_id.cdscat"
+ " and tobjtcm.comp_id.cdensg = tperfql.comp_id.cdensg"

The addition to the select clause causes an exception :
"HibernateQueryException: undefined alias: tobjtcm"

The underlying database is Oracle 8i (which I am aware is not involved up to this point, but might help to find the proper syntax).

I do not know much of SQL nor HQL so probably this code is quite naive.
Has anyone a working example of a sum of products query involving more than one table (HQL + tables mapping) ?

Thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 18, 2003 4:42 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
Quote:
sum(tperfql.mtvteht * tobjtcm.txevvtettcp1)


HQL doesn't support arithmetic expressions in the select clause :(

Hopefully the new query parser slated for 2.2 will help solve this problem.


Top
 Profile  
 
 Post subject: Re: Sum of products
PostPosted: Thu Dec 18, 2003 4:56 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
[quote="Fran


Top
 Profile  
 
 Post subject: Re: Sum of products
PostPosted: Thu Dec 18, 2003 5:47 am 
Newbie

Joined: Thu Dec 18, 2003 4:09 am
Posts: 3
david wrote:
[quote="Fran


Top
 Profile  
 
 Post subject: Re: Sum of products
PostPosted: Thu Dec 18, 2003 5:50 am 
Newbie

Joined: Thu Dec 18, 2003 4:09 am
Posts: 3
[quote="Fran


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.