-->
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: distinct in Criteria
PostPosted: Wed Dec 03, 2003 4:52 pm 
Newbie

Joined: Wed Dec 03, 2003 4:41 pm
Posts: 2
I have a Parent object which has many children. Using HQL I can do a simple query to find parents which have children of a specified age like so:
"select parent from Parent as parent join Children as child where child.age=10"

I think I just learned today that if a parent has two children age 10 (twins) then I get the same parent twice. Which in SQL terms makes sense because I joined to the children collection so I end up with two result rows, one for each child. In HQL I can get the result I want by adding 'distinct' to the query.

"select distinct parent from Parent as parent join Children as child where child.age=10"

Gives me all the parents that have a child of that age, but each parent only once, just what I want. I can get the first result, the same parent repeated for each child, using the Criteria api but I can't figure out how to get the distinct list. Can I?


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 7:33 am 
Hibernate Team
Hibernate Team

Joined: Tue Aug 26, 2003 12:50 pm
Posts: 5130
Location: Melbourne, Australia
There is no way to specify a "distinct" Criteria at this time. I am not averse to adding this. Request it in JIRA.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 04, 2003 9:01 am 
Newbie

Joined: Wed Dec 03, 2003 4:41 pm
Posts: 2
Thanks Gavin, I'll do that. The Criteria API is great for the type of ad-hoc reporting that I'm doing in this app.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Mar 11, 2004 1:15 pm 
Regular
Regular

Joined: Thu Jan 29, 2004 10:34 am
Posts: 52
Location: Austin, TX
so the distinct feature in yet? (off of JIRA?)

my workaround lies on the java side. i.e. to make the returned collection unique through a Set.


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.