-->
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: How do you use the HQL ORDER BY on an indexed collection?
PostPosted: Mon Apr 17, 2006 12:30 pm 
Beginner
Beginner

Joined: Thu Dec 09, 2004 3:19 pm
Posts: 34
Hibernate version:
2.1

In the WHERE clause you can specify the key with props.['key'] which is incredibly convenient. How do I order by the same value though? In the ORDER BY clause, the same syntax gives me a " net.sf.hibernate.QueryException: Incorrect query syntax "

Here's the query: select distinct ga from GroupAsset ga where ga.metadata.properties['Version'] between :verStart and :verEnd order by ga.metadata.properties['Version'] asc

If I replace ga.metadata.properties['Version'] with ga.status, the query works, so the problem is the indexed collection syntax in the ORDER BY clause. Presumably it's simply not allowed in the order by clause, but what's the alternative to get the equivalent ordering?

Thanks,
Chris


Top
 Profile  
 
 Post subject:
PostPosted: Mon Apr 17, 2006 1:23 pm 
Expert
Expert

Joined: Fri Jul 22, 2005 2:42 pm
Posts: 670
Location: Seattle, WA
For indexed collection order is fixed: index defines the collection order.

If you want to reorder the collection then you can do it programmatically /Collections.sort() /, but make sure that you do it outside of transaction otherwise H will try to prsist the collection with using new indexes.

_________________
--------------
Konstantin

SourceLabs - dependable OpenSource systems


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 12:25 pm 
Newbie

Joined: Thu Apr 20, 2006 9:35 am
Posts: 10
Hi,

I have the same problem/wich...

Is it still not possible to do something like that :

Code:
...order by map['key']...


Thanks for your response.


Top
 Profile  
 
 Post subject:
PostPosted: Tue May 16, 2006 1:07 pm 
Expert
Expert

Joined: Tue Apr 25, 2006 12:04 pm
Posts: 260
See section 6.3 in reference documentation. You could use createFilter to order collection.

sortedUsers = s.createFilter( group.getUsers(), "order by this.name" ).list();


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.