-->
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.  [ 3 posts ] 
Author Message
 Post subject: Hql query on getting distinct children
PostPosted: Tue Nov 28, 2006 10:29 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
asp 2.0 Nhibernate 1.2.0.Beta1

I have a Customer entity that has a many to one relationship with a Location entity.


I need a piece of HQL that returns a distinct alphabetical sorted List of Locations used by Customers.


Im having trouble getting my head around how to do this in HQL, in SQL it would be something like this:

Code:
SELECT DISTINCT LocationID
FROM         Customers
ORDER BY LocationID


How do i do this in HQL? bearing in mind i don't want a list of LocationIDs returned, i want a list of Location Objects.

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 5:20 am 
Regular
Regular

Joined: Fri Nov 04, 2005 12:37 pm
Posts: 81
Code:
<query name="Location.GetAllUsed"><![CDATA[select distinct Location from (select cus.Location from Customer cus)]]></query>


I tried this, with no joy.


Can anyone help? or is my question too dumb or something?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 29, 2006 5:35 am 
Newbie

Joined: Mon Mar 27, 2006 10:24 am
Posts: 8
Location: Malmoe, Sweden
this should do the trick
Code:
IList _list = session.Find("select distinct cus.Location from Customer cus");


/Floda


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