-->
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: SQL setResultTransformer question
PostPosted: Wed Sep 27, 2006 5:34 pm 
Newbie

Joined: Thu Sep 21, 2006 7:12 am
Posts: 6
When using the following code:

List ReportResult = session.createSQLQuery("select ......").setResultTransformer(Transformers.ALIAS_TO_ENTITY_MAP).list();
Map m = ( Map ) ReportResult.get(0);
Iterator keys = m.keySet().iterator();
while (keys.hasNext()) {
logger.debug( (String)keys.next());
}

the order of the returned keys does not correspond to the order of the fields in the query, as a matter of fact, it does not correspond to any specific order. Shouldn't this leave the order unchanged?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 1:32 pm 
Newbie

Joined: Thu Sep 21, 2006 7:12 am
Posts: 6
shouldn't this be filed as a bug?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 1:41 pm 
Regular
Regular

Joined: Tue Sep 26, 2006 11:37 am
Posts: 115
Location: Sacramento, CA
From http://java.sun.com/j2se/1.4.2/docs/api ... l/Map.html

"The order of a map is defined as the order in which the iterators on the map's collection views return their elements. Some map implementations, like the TreeMap class, make specific guarantees as to their order; others, like the HashMap class, do not."

It seems to me that the Map itself may not guarantee any order. Am I missing something? Is there some hibernate doc/spec that guarantees the order for the implementation of that particular map?

Marius


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 3:02 pm 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 6:10 am
Posts: 8615
Location: Neuchatel, Switzerland (Danish)
the main purpose of the map is to be able to access it by an alias key instead of by a integer position into an Object[], so no it is not a bug.

If you want to maintain the sequence then customize the resulttransformer to use something like a SequencedHashMap to get the behavior you want.

_________________
Max
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Thu Sep 28, 2006 4:29 pm 
Beginner
Beginner

Joined: Thu Aug 24, 2006 6:01 am
Posts: 49
Location: sophia-antipolis, France
I don't think this is a bug. Maps don't have a guaranteed ordering of keys. If you want a repeatable order, you have to use LinkedHashMap.

oops, I didn't see the previous response.


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.