-->
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: Ordering of selected fields in <sql-query/>
PostPosted: Thu Dec 08, 2005 5:17 pm 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Hibernate version: 3.1

I have some named sql-query elements in my mapping. They work fine except that the items in the returned object array are in a different order than they are specified in the mapping.

In this example, I would expect...
[a][b][c]
[a][b][c]
[a][b][c]...

Instead, I get...
[c][a][b]
[c][a][b]
[c][a][b]...


Code:
   
<sql-query name="myQuery">
      <return alias="a" class="ClassA"/>
      <return alias="b" class="ClassB"/>
      <return-scalar column="c" type="long"/>
      <![CDATA[
         select
            {a.*},
            {b.*},
            c
         from
            ......
                  ]]>
   </sql-query>



If I can't fix this, is there a way to make the results a Map, like you can with HQL? I think i'd rather do that anyway.

Thank you


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 08, 2005 6:03 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
hmmm...what happens if you do this via the createSQLQuery api ?

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Sun Dec 11, 2005 9:08 pm 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Sorry for the delayed reply. I had to piece a bunch of things back together before I could test createSQLQuery.
Anyway, results are the same. I did a little additional testing and it appears that if I mix addEntity() and addScalar(), the scalar values are always moved to the front of object array result.

In other word:

createSQLQuery("...")
.addScalar("a",Hibernate.LONG)
.addEntity("b",EquipmentType.class)
.list();
... will give me...
[scalar][entity]


createSQLQuery("...")
.addEntity("b",EquipmentType.class)
.addScalar("a",Hibernate.LONG)
.list();
... will give me...
[scalar][entity]


createSQLQuery("...")
.addScalar("a",Hibernate.LONG)
.addEntity("b",EquipmentType.class)
.addScalar("c",Hibernate.LONG)
.list();
... will give me...
[scalar][scalar][entity]

... etc


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 2:38 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
ah yes - that is one quirk that I don't like, but that is unfortunately reality. scalars always comes first.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 12, 2005 2:46 am 
Beginner
Beginner

Joined: Fri Nov 04, 2005 3:51 pm
Posts: 32
Ok. As long as I know it's consistent now, I can work with that. Thank you.


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.