-->
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.  [ 1 post ] 
Author Message
 Post subject: HQL: how to write "select distinct" query
PostPosted: Mon Feb 18, 2008 5:15 am 
Newbie

Joined: Mon Feb 18, 2008 4:46 am
Posts: 6
Hi,

I want to write a "select distinct" query in HQL.
my query has a lot of joins, so i have a lot of duplicates in the results -
and this cause a performace issue.

The idea of the query is as follows (see the query below):
I have two entities "A" and "B".
"A" has a reference to "B" (Many-to-Many).
i want all the objects of B.
i also want some of the data of B returning eagerly.

The problem is i get a lot of duplicates of "b"
in numbers i get 70,00 instead of 700.

i work above "sql server 2000",
and i understand there is problem using "select distinct" (in hibernate)
over this database - beacause the generated sql is invalid (i tried it and it didnt work).

i also tried "group by" on "b", but the generated sql is "group by" only on the "b.id" - which doesn't work.


the query is something as the following:
==========================

select b
from A a
inner join a.b b
left join fetch b.some_object1
left join fetch b.some_object2
left join fetch b.some_object2.some_object3
left join fetch b.some_object4
left join fetch b.some_object5
left join fetch b.some_object6
where a.some_field=true


thanks,
Eran.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 1 post ] 

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.