-->
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: Distinct with ICriteria (just one column)
PostPosted: Wed Jun 28, 2006 2:40 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
Hello all...
I have the follow HQL:
Code:
IList _list = session.Find("select distinct geral.Estate from TowerGeral geral");

So, I got all distincts estates from my Table!


I´m trying to do the same thing with ICriteria... I done that:
Code:
ICriteria _crit = session.CreateCriteria(typeof(TowerGeral));
_crit.Add(Expression.Eq("Estate", __estate));
_crit.SetResultTransformer(NHibernate.CriteriaUtil.DistinctRootEntity);               


I think with SetResultTransformer I get distinct entitys... But I need distinct Estates.

Example:
Table:
1 - X - 30500 - 2006
2 - Y - 43000 - 2004
3 - W - 2300 - 2002
4 - X - 299 - 2003
5 - W - 876 - 1999

I´d like to return only X,Y,W once like in previous HQL... Help?

[]´s


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 10:26 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
Just to let the things clear, I´d like do that(HQL) with ICriteria:

Code:
select distinct geral.Estate from TowerGeral geral


Please help!


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 4:02 pm 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
I found setProjection function on Hibernate's v3 documentation ... Thats exactly what I need... How can I use that function on NH?

I need to do something like that
Code:
List products=session.createCriteria(Product.class)
     . setProjection(Projection.property(\"name\"))
     .list();



Top
 Profile  
 
 Post subject:
PostPosted: Thu Jun 29, 2006 5:43 pm 
Pro
Pro

Joined: Fri Nov 19, 2004 5:52 pm
Posts: 232
Location: Chicago, IL
My guess is that maybe it isn't possible because that is a feature that is new to Hibernate 3 and NHibernate is based on Hibernate 2.1. That's just a guess though. Hopefully someone else will chime in and state more authoritively whether you can do it.

If nothing else, I guess you could just use StringBuilder and build up the HQL query at run-time, but, I'm guessing this is pretty obvious to you and that's not what you want.


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 30, 2006 8:51 am 
Beginner
Beginner

Joined: Wed Jun 28, 2006 2:03 pm
Posts: 22
jemiller wrote:
My guess is that maybe it isn't possible because that is a feature that is new to Hibernate 3 and NHibernate is based on Hibernate 2.1. That's just a guess though. Hopefully someone else will chime in and state more authoritively whether you can do it.

If nothing else, I guess you could just use StringBuilder and build up the HQL query at run-time, but, I'm guessing this is pretty obvious to you and that's not what you want.


Ty for the reply!
Yes, I can do that easily with HQL, but in my case I´d like to use ICriteria! Anyone more can help-me?


ty


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.