-->
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.  [ 4 posts ] 
Author Message
 Post subject: [Possible bug] Multiplication inside aggregations
PostPosted: Mon Aug 30, 2004 12:11 pm 
Newbie

Joined: Mon Aug 30, 2004 11:35 am
Posts: 1
Hibernate version: 2.1.4
Database: PostgreSQL

Looks like there is a problem with multiplications inside aggregation functions (select sum( a * b)...)

(I am using Spiring's HibernateTemplate to run this query)
Code:
    private static final String RECOMENDATIONS_QUERY =
            "select ra.recommendationId, sum(ra.allocation * ra.allocation) " +
            "from " + RecommendedAllocation.class.getName() + " ra " +
            "group by ra.recommendationId";

    public List getRecommendationDetails() {
        return this.getHibernateTemplate().find(RECOMENDATIONS_QUERY);
    }


Hibernate generates valid SQL:
Code:
select recommende0_.recommendation_id as x0_0_,
    sum(recommende0_.allocation*recommende0_.allocation) as x1_0_
from recommended_allocations recommende0_
group by  recommende0_.recommendation_id


I am getting NullPointerException from postgress when resultset is wrapped into array of objects.

The problem is in SelectParser.token() method. It has a special treatment for '*' inside aggreagte function. i.e. '*' inside aggregation considered as count(*) and new scalar column added to query. Later Loader tryes to get value for this non-existing column which causes NullPointerException.

Changing '*' into '+' or '/' in the original query fixes the problem.

Stack trace below:
java.lang.NullPointerException
at org.postgresql.util.PSQLException.getSQLState(PSQLException.java:227)
at net.sf.hibernate.util.JDBCExceptionReporter.logExceptions(JDBCExceptionReporter.java:38)
at net.sf.hibernate.loader.Loader.doQuery(Loader.java:230)
at net.sf.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:133)
at net.sf.hibernate.loader.Loader.doList(Loader.java:955)
at net.sf.hibernate.loader.Loader.list(Loader.java:946)
at net.sf.hibernate.hql.QueryTranslator.list(QueryTranslator.java:846)
at net.sf.hibernate.impl.SessionImpl.find(SessionImpl.java:1543)
at net.sf.hibernate.impl.QueryImpl.list(QueryImpl.java:39)
at org.springframework.orm.hibernate.HibernateTemplate$17.doInHibernate(HibernateTemplate.java:331)
at org.springframework.orm.hibernate.HibernateTemplate.execute(HibernateTemplate.java:150)
at org.springframework.orm.hibernate.HibernateTemplate.executeFind(HibernateTemplate.java:170)
at org.springframework.orm.hibernate.HibernateTemplate.find(HibernateTemplate.java:328)


Top
 Profile  
 
 Post subject:
PostPosted: Mon Aug 30, 2004 6:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 7:19 pm
Posts: 2364
Location: Brisbane, Australia
Correction, It is a feature that is not currently supported, eg, no expressions in the select clause. This will be attended to at some point once the AST parser is offically integrated into the Hibernate 3.0 development branch.


Top
 Profile  
 
 Post subject: If sum(myObject.myInt * myObject.myMoney)what is return type
PostPosted: Mon Sep 27, 2004 9:12 pm 
Beginner
Beginner

Joined: Wed May 12, 2004 2:52 pm
Posts: 36
David,

perhaps you can shed some light on this. How would you determine the return type of the above? I am using the result in a constructor of a DTO class. Hibernate complains that it cant find an appropriate constructor. I don't know what type hibernate is returning. Is there a way to debug this?

Joshua


Top
 Profile  
 
 Post subject:
PostPosted: Tue Sep 28, 2004 5:52 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
This is not supported - at all


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