-->
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: distinc in HQL
PostPosted: Wed Dec 27, 2006 4:27 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
Hi, I have the following query

select distinct parent from parent left join fetch child where parent.name like ?
return getSession()
.createQuery(hqlString)
.setString("searchString",name)
.setFirstResult(startPosition)
.setMaxResults(maxResult)
.list();

I keep getting duplicate parent back if parent has 1 or more children.

is the SQL correct? How to use distinct correctly?

The child is a set in parent defined in parent.hbm.xml.


Top
 Profile  
 
 Post subject: Re: distinc in HQL
PostPosted: Wed Dec 27, 2006 4:37 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
mwang168 wrote:
Hi, I have the following query

select distinct parent from parent left join fetch child where parent.name like ?
return getSession()
.createQuery(hqlString)
.setString("searchString",name)
.setFirstResult(startPosition)
.setMaxResults(maxResult)
.list();

I keep getting duplicate parent back if parent has 1 or more children.

is the SQL correct? How to use distinct correctly?

The child is a set in parent defined in parent.hbm.xml.


thats correct put the list you are getting into set ... to remove dups

_________________
Don't forget to rate


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 4:43 pm 
Beginner
Beginner

Joined: Thu Oct 05, 2006 4:00 pm
Posts: 22
thanks for the quick reply. is there a more efficient way to do this?

Currently I am using a TreeSet to sort it. is there a short cut API convert from list to set?


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 27, 2006 5:00 pm 
Senior
Senior

Joined: Sun Jun 04, 2006 1:58 am
Posts: 136
mwang168 wrote:
thanks for the quick reply. is there a more efficient way to do this?

Currently I am using a TreeSet to sort it. is there a short cut API convert from list to set?


I dont think there is ..( i might be wrong ) for HQL ...but there is
http://www.hibernate.org/hib_docs/v3/api/org/hibernate/criterion/CriteriaSpecification.html#DISTINCT_ROOT_ENTITY
if you are using criteria

_________________
Don't forget to rate


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.