-->
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: query help
PostPosted: Fri Mar 19, 2004 10:47 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
hello,

i was hoping someone could tell me where i've gone wrong on this query, i've tried executing the sql generated and that works fine.

thanks, cam

HQL
Code:
select sum(i.quantity * i.unitPrice) from OrderItem as i where i.order.account = ?


SQL
Code:
select sum(orderitem0_.quantity*orderitem0_.unitPrice) as x0_0_ from OrderItem orderitem0_, Orders order1_ where (order1_.account=?  and orderitem0_.orderId=order1_.id)


Error
Code:
java.sql.SQLException: Column 'x1_0_' not found.
   at com.mysql.jdbc.ResultSet.findColumn(ResultSet.java:2260)
   at com.mysql.jdbc.ResultSet.getInt(ResultSet.java:1282)
   at org.apache.commons.dbcp.DelegatingResultSet.getInt(DelegatingResultSet.java:220)
   at net.sf.hibernate.type.IntegerType.get(IntegerType.java:18)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:62)
   at net.sf.hibernate.type.NullableType.nullSafeGet(NullableType.java:53)
   at net.sf.hibernate.hql.QueryTranslator.getResultColumnOrRow(QueryTranslator.java:981)
   at net.sf.hibernate.loader.Loader.doQuery(Loader.java:221)
   at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:132)
   at net.sf.hibernate.loader.Loader.doList(Loader.java:949)
   at net.sf.hibernate.loader.Loader.list(Loader.java:940)
   at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:833)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1475)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1454)
   at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1450)


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 11:10 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
I think you will have to register the sum() function with the dialect. Take a look at MySqlDialect in CVS v22branch or at OracleDialect, there you can see how to do it.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Mar 19, 2004 11:38 am 
Beginner
Beginner

Joined: Fri Oct 10, 2003 10:12 am
Posts: 39
so are you saying that i should extend the mysql dialet? i'm a bit confused on what i should need to register the sum function - the follwoing query works fine:

Code:
select sum(t.amount) from Transaction as t where t.account = ?


is it because i want to do a calculation within the sum?
cam


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.