-->
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.  [ 1 post ] 
Author Message
 Post subject: Bug in grouping SQLQuery without aliases?
PostPosted: Fri Apr 01, 2011 5:30 am 
Newbie

Joined: Mon May 24, 2010 9:12 am
Posts: 3
Hi, I'm new to this forum, so hello to everyone!

I'm using Hibernate 3.6.2.
I have have a very simple SQL query trying to get the max of some column in a table (just a table of coordinates x,y,z..)

Code:
HibernateUtil.getCurrentSession().createSQLQuery("select max(x), max(y), max(z) from locations").uniqueResult();


Executing this returns an Object[] with 3 values each equals to the first max(x), say [95, 95, 95] while the correct result would be, let's say, [95, 13, 1]

If I assign an alias to each column in the sqlquery the result is correct:
Code:
HibernateUtil.getCurrentSession().createSQLQuery("select max(x) as x, max(y) as y, max(z) as z from locations").uniqueResult();



I've searched in code and I found that in class org.hibernate.type.descriptor.sql.IntegerTypeDescriptor is called this method:
Code:
   public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
      return new BasicExtractor<X>( javaTypeDescriptor, this ) {
         @Override
         protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
            return javaTypeDescriptor.wrap( rs.getInt( name ), options );
         }
      };
   }


If I don't assign an alias to columns then all 3 aliases are populated with "", so this line:
Code:
return javaTypeDescriptor.wrap( rs.getInt( name ), options );

calling a ResultSet method gives the first column with the specified alias (which is equals in all 3 columns).

Now, I've learned the lesson and I put everytime an alias when executing some query, but could we say this is a bug?


Thanks for your opinion...
Luca


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.