-->
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: Please help with simple order by problem - thanks
PostPosted: Wed Jul 25, 2007 8:42 am 
Newbie

Joined: Wed Jul 25, 2007 7:46 am
Posts: 4

How come this simple order by does not work? Here is the code


Session session = f.openSession();
Transaction tx = session.beginTransaction();
classIds=new HashSet();

List result=null;
result = session.createQuery("FROM KClassIds order by classId").list();

Iterator iter = result.iterator();
while (iter.hasNext())
{
if(debug) System.out.println("BClassIds:Loading KClassIds");
KClassIds tkcids = (KClassIds) iter.next();

KClassIds kcids=new KClassIds();
kcids.setClassId(tkcids.getClassId());
kcids.setName(tkcids.getName());
kcids.display();

classIds.add(kcids);
}
session.close();

Here is the mapping

<class name="KClassIds" table="classes">
<id name="classId" column="class_id" type="string" length="180"></id>
<property name="name" column="name" type="string" length="240"/>
</class>

Any/all help greatly appreciated, thanks in advance!

jim s



Top
 Profile  
 
 Post subject: What output are you getting?
PostPosted: Wed Jul 25, 2007 2:33 pm 
Newbie

Joined: Thu Jun 07, 2007 11:28 am
Posts: 2
Location: Woking, UK
Could you show the data from the table, and the output you're getting?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Jul 25, 2007 6:26 pm 
Expert
Expert

Joined: Fri Jul 13, 2007 8:18 am
Posts: 370
Location: london
HashSet is an unordered collection so if you iterate over the classIds variable, don't expect items to be returned in the same order they came out of the database. Your SQL is almost certainly ok.

Mike


Top
 Profile  
 
 Post subject:
PostPosted: Sat Jul 28, 2007 8:25 am 
Newbie

Joined: Wed Jul 25, 2007 7:46 am
Posts: 4
Thanks that makes sense. I solved the problem by using a SortedSet/TreeSet. Thanks to all that posted.

jim s


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.