-->
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: Native query column name to result mapping.
PostPosted: Wed Nov 04, 2009 6:40 pm 
Newbie

Joined: Wed Nov 04, 2009 6:34 pm
Posts: 1
I don't know if this is intended behaviour or not, but I just spent some time debugging this.

If you execute a native query using hibernate, and the resulting column names are identical, all your columns will have the same result.

Take the following example query.

select * from
( select count(distinct tr.id) from <…> where <…>) as t0 join
( select count(distinct tr.id) from <…> where <…>) as t1 join
( select count(distinct tr.id) from <…> where <…>) as t2 join
( select count(distinct tr.id) from <…> where <…>) as t3

MySQL yields

count(distinct tr.id) count(distinct tr.id) count(distinct tr.id) count(distinct tr.id)
122 111 239 208

Hibernate result yields an Object[] = {122,122,122,122};

select * from
( select count(distinct tr.id) as col0 from <…> where <…>) as t0 join
( select count(distinct tr.id) as col1 from <…> where <…>) as t1 join
( select count(distinct tr.id) as col2 from <…> where <…>) as t2 join
( select count(distinct tr.id) as col3 from <…> where <…>) as t3

MySQL yields

col0 col1 col2 col3
122 111 239 208

And Hibernate yields the correct result Object[] = {122,111,239,208}


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.