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: HQL & Collections
PostPosted: Tue Nov 07, 2006 6:48 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear NHibernate users,

when we want to get a collection, we can use the elements keyword in our hql, but what if we want to get the Ids of the collection objects, ex:

string hql="SELECT elements(myCollection) from Category where ..."; works fine, we get all the Collection objects .
but what if i want to get only the ids of this Collection in my hql, cause i don;t need the other properties of the collection, i only need to access the id property for each object of the collection ...

Regards,
JojoRico

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 8:01 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
You could try:

Code:
SELECT M.Id from Category C, C.myCollection M where ...


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 07, 2006 9:38 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
It worked !!!
but Do you know (in this hql) if the collection attributes are all loaded and then there is a filtration in order to get the Id property, or is the Id property directly loaded from the db instead of loading all the properties than filtering the id?

Thanks a lot :)

_________________
In Code We Trust


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 6:10 am 
Beginner
Beginner

Joined: Fri Oct 20, 2006 8:02 am
Posts: 36
look at the SQL generated to take the values.

I made a test myself and the select was something like this:

Code:
SELECT M.Id from TBL_Category C, TBL_myCollection M where C.Id = M.ID


but if you want to be sure, watch out your log, or use the nqa application to test and see your HQL.

If you don't know nqa, i really like it:
http://www.ayende.com/projects/nhibernate-query-analyzer/downloads.aspx


Top
 Profile  
 
 Post subject:
PostPosted: Wed Nov 08, 2006 10:52 am 
Regular
Regular

Joined: Mon Aug 28, 2006 6:35 am
Posts: 66
Location: Middle East
Dear anuarneto,

thanks a lot
I've already asked about some hql analyser but nobody have replied ..

Regards,
Jojo

_________________
In Code We Trust


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.