-->
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: Performace issue
PostPosted: Mon Jun 28, 2010 12:09 pm 
Newbie

Joined: Mon Feb 21, 2005 2:15 pm
Posts: 9
Hello,

I am using a left join fetch in my HQL for improved performace.
It returns duplicate records because of the left join fetch since hibernate generates a left outer join (i am using distinct).Is there a way to avoid the duplicate records other than using Hibernate.initialize(obj) call.
I want to avoid Hibernate.initialize(obj) because it fires a query each time Hibernate.initialize(obj) is called.

String hql = "select distint a from A left join fetch a.B b where ....";
This generates a query as :
select distinct a.*, b.* from A a left outer join B b on ....
where ....

How can make hibernate generate
select distinct a.* from A a left outer join B b on ....
where ....

Thanks,
Gayatri


Top
 Profile  
 
 Post subject: Re: Performace issue
PostPosted: Mon Jun 28, 2010 4:11 pm 
Newbie

Joined: Wed Feb 10, 2010 7:19 pm
Posts: 12
For better understanding you need to post your mapping files and relation of the objects.
For distinct you can use uniqueResults on the query object.


Top
 Profile  
 
 Post subject: Re: Performace issue
PostPosted: Tue Jun 29, 2010 12:38 am 
Newbie

Joined: Mon Jun 21, 2010 1:36 pm
Posts: 14
Take a look at the following Hibernate FAQ link. It answers your question.

http://web.archive.org/web/200702021455 ... 7.html#A12


-BJ


Top
 Profile  
 
 Post subject: Re: Performace issue
PostPosted: Wed Jun 30, 2010 11:54 am 
Newbie

Joined: Mon Feb 21, 2005 2:15 pm
Posts: 9
Thanks for the replies.

Query.uniqueResultSet() works if there is only 1 object in the resultset, but in my scenario I have multiple objects returned. With a left join fetch it was returning duplicates i.e if I expect my resultset to be [1, 2, 3], it would return [1, 1, 2, 3, 3].
I resolved this issue by using
query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);

Thanks,
Gayatri


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.