-->
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.  [ 7 posts ] 
Author Message
 Post subject: Sorting Set
PostPosted: Fri Feb 06, 2004 6:30 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
Hi,

I have a Entity class, which have a Set property, that will be use as a Set of String. When I save it, I use HashSet, so the collection of String is not sorted when it go to database. I'm not using the attribute "sort" or "order-by" in the mapping.

When I'm querying it, is it possible to get that collection of String sorted using Hibernate Query Language?


Top
 Profile  
 
 Post subject:
PostPosted: Fri Feb 06, 2004 7:36 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
Only if you use HQL like

Code:
select e.stringProperty from Entity e order by e.stringProperty


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 5:41 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
No, no, that's not what I mean.
The property is a Set of String, not String.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 6:40 am 
Hibernate Team
Hibernate Team

Joined: Tue Sep 09, 2003 2:10 pm
Posts: 3246
Location: Passau, Germany
You mean querying for an object and get the associated collection sorted without using sort attribute? No, not possible.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 7:34 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
I've just found how to do it.

select elements(e.setProperty)
from entity e
where e.id=some_value
order by set_element_column_name

At first I keep on using alias of the entity for the order by, which always gave me error.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Feb 10, 2004 8:11 am 
Newbie

Joined: Thu Oct 23, 2003 6:39 pm
Posts: 16
or you could:

Code:
List sorted = sess.createFilter(entity.getSet(), "order by this.someproperty").list;

milx


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 12, 2004 6:00 am 
Beginner
Beginner

Joined: Mon Jan 26, 2004 3:31 am
Posts: 20
Location: Jakarta, Indonesia
milx wrote:
or you could:

Code:
List sorted = sess.createFilter(entity.getSet(), "order by this.someproperty").list;

milx


Thanks! That's a much better way than mine


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 7 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.